Code Monkey home page Code Monkey logo

flutter-cookbook's Introduction

Flutter Cookbook

Flutter Cookbook

This is the code repository for Flutter Cookbook, published by Packt.

Over 100 proven techniques and solutions for app development with Flutter 2.2 and Dart

What is this book about?

Flutter is an open-source framework for building mobile, web, and desktop apps using the Dart language. With this recipe-based guide, which focuses on robust app design and core principles, you’ll learn how to solve cross-platform development issues in a practical way.

This book covers the following exciting features:

  • Build native iOS and Android apps from a single codebase
  • Discover how to develop and think like a Dart programmer
  • Find simple solutions to complex problems by applying the principle of composition over inheritance
  • Create reusable architecture that can be applied to any type of app
  • Quickly debug and solve problems before users can see them

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

void variablePlayground() {
basicTypes();
untypedVariables();
typeInterpolation();
immutableVariables();
}

Following is what you need for this book:

This app development book is for beginner to intermediate-level developers who want to become mobile developers. Basic knowledge of modern programming languages such as JavaScript, Swift, Kotlin, Java, Objective-C, or C# will help you to understand the concepts covered in the book more easily.

With the following software and hardware list you can run all code files present in the book (Chapter 1-15).

Software and Hardware List

Chapter Software required OS required
1-15 Visual Studio Code, Android Studio, or IntelliJ Ide Windows, Mac OS X, and Linux
1-15 Flutter SDK Windows, Mac OS X, and Linux
1-15 An emulator/simulator or an iOS or Android device Windows, macOS, or Linux (macOS is needed only for iOS)

In order to create apps for iOS, you will need a Mac.

Errata

  • Page 66, Section: How to do it... Step 3(code snippet line 3): final MapString, int ages = { ... should be final Map ages = { ...
  • Page 133, top line of text on the page : 5. Fill in the Flexible section. Don't forget to hot reload while writing the code: should be 5. Fill in the _buildFlexible method. Don't forget to hot reload while writing the code:
  • Page 168, last code line of 2nd point : State createState() => StopWatchState(); should be State createState() => _StopWatchState(); // This needs to have an underscore in order to be treated as private.
  • Page 168, 1st code line of 3rd point : class StopWatchState extends State { should be class _StopWatchState extends State {

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Get to Know the Authors

Simone Alessandria wrote his first program when he was 12. It was a text-based fantasy game for the Commodore 64. Now, he is a trainer (MCT), author, speaker, passionate software architect, and always a proud coder. He is the founder and owner of Softwarehouse.it. His mission is to help developers achieve more through training and mentoring. He has authored several books on Flutter, including Flutter Projects, published by Packt, and web courses on Pluralsight and Udemy.

Brian's career had him working on video games, eCommerce, productivity, finance, and travel apps. After spending years working as an iOS and Android developer, he sees Flutter as the next big pillar for mobile.

Other books by the author

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781838823382

flutter-cookbook's People

Contributors

akhilnairnp avatar bkayfitz avatar packt-itservice avatar packtaamira avatar packtutkarshr avatar shubham763 avatar simoales avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter-cookbook's Issues

Update code for null-safety

Sound null safety is available in Dart 2.12 and Flutter 2.

This issue could be a big problem for a beginner using the latest version of Dart.

No geolocator permissions hint

I had to look up answer myself. Added these lines to android/app/src/debug/AndroidManifest.xml:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Compile error on "Using the device camera (p.510)"

Hi!

I am trying to get the device camera example from the cookbook running but get the following compile error. I used the main.dart, camera.dart, picture.dart and pubspec.yaml file provided here without changing anything.

This is the error stack I am getting:

Running "flutter pub get" in camera_app...
The plugin firebase_mlkit_language uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.
Launching lib/main.dart on HUAWEI TAG L21 in debug mode...
Running Gradle task 'assembleDebug'...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:138: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:142: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:146: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:150: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:154: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:158: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA);
^
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java:162: warning: [deprecation] get(int,int) in CamcorderProfile has been deprecated
return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
^
error: warnings found and -Werror specified
/Users/stefvenmans/Development/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.7.0+4/android/src/main/java/io/flutter/plugins/camera/media/MediaRecorderBuilder.java:15: warning: [deprecation] MediaRecorder() in MediaRecorder has been deprecated
return new MediaRecorder();
^
1 error
8 warnings

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':camera:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 31s
*********************************************************
WARNING: This version of firebase_mlkit_language will break your Android build if it or its dependencies aren't compatible with AndroidX.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
*********************************************************
Exception: Gradle task assembleDebug failed with exit code 1

Future<dynamic> can't be returned

Hi I'm doing the excercise on chapter 7 (Unfortunately my ebook doesn't show the page no) and I get the following error in main.dart file on line 41: return completer.future (underlined red):

A value of type 'Future<dynamic>' can't be returned from the method 'getNumber' because it has a return type of 'Future<int>'.

How to turn the completer into type future?

type 'Null' is not a subtype of type 'String'

i'm using a new version of flutter
i get this error: type 'Null' is not a subtype of type 'String'

at the 3rd this line of the code (plan_services.dart):

  Plan createPlan(String name) {
    final model = _repository.create();
    print('my name $name');                                           //the name in not null here
    final plan = Plan.fromModel(model)..name = name;            //error here
    savePlan(plan);
    return plan;
  }

after debugging, i got name=null here (plan.dart)

  Plan.fromModel(Model model)
      : id = model.id,
        name = model.data['name'],             //the name is null here
        tasks = model.data['task']
                ?.map<Task>((task) => Task.fromModel(task))
                ?.toList() ??
            <Task>[];

can you explain why? thank you

related to null safety?

For the pizza json chapter 8 I believe with a factory constructor, null cannot be returned. Please update the code. I have no idea what purpose the factory serves now except if there is a cache of instantiated pizzas in the pizza class which then could be used to optimize a bit by not having to instantiate every instance. But I am unclear on the "how" this works under the hood.

Mastering layout Dog/Beach is wrong

If you debug in Chrome and stretch the window's width, the heading: value text is left at the left edge while everything else centers. The stack should only include the background and photo and then be encapsulated by a Column so you can put the other text under the Stack in the column, all as children of the Column. Thus if you probably rotate screen to Landscape on a device the same thing happens. It's a shame because it's a good book but you did not test out your code a bit more to make it robust for various use cases. As of now it only looks nice when you have a device in Portrait mode or Chrome window at its narrowest width possible.

Chapters 4 and 5

Those chapters do not work due to null safety in Flutter 2.5 - it would be great if those could be updated

Using Firebase, Storing files in the cloud: Missed Step

The recipe that shows how to upload the local file to the Cloud Storage clearly misses the step in which the Cloud Storage has to be "configured first", otherwise the Firebase will report the 404 error and a cryptic message ("File Not Found").
As someone who didn't work with the Firebase cloud storage before, it took me several attempts to figure out what needs to be done and for a beginner this may end up in a complete confusion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.