Flutter Cookbook, published by Packt

Overview

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 = { ...

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

Comments
  • related to null safety?

    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.

    opened by nyck33 2
  • Where can I find the images used in the coding examples?

    Where can I find the images used in the coding examples?

    I like the book so far but I am a bit lost now: Where do I find the images used f.e. textiles.jpg and women_shopping.jpg in chapter 4? Do I have to download some random images and name them as such on my own?

    opened by Jaykocha 1
  • Mastering layout Dog/Beach is wrong

    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.

    opened by nyck33 0
  • Using Firebase, Storing files in the cloud: Missed Step

    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.

    opened by carambathat 0
  • Future<dynamic> can't be returned

    Future 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?

    opened by sslaia 1
  • Compile error on

    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

    opened by stefvenmans 0
  • type 'Null' is not a subtype of type 'String'

    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

    opened by amkfat 1
  • No geolocator permissions hint

    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" />
    
    opened by roboli 2
Owner
Packt
Providing books, eBooks, video tutorials, and articles for IT developers, administrators, and users.
Packt
This is an animated app used to control Tesla Car which is on progress and will be published soon

Animated Tesla App Conect using Flutter Packages we are using: flutter_svg: link We will cover how to use ImplicitlyAnimatedWidge and how to use multi

null 1 Nov 13, 2021
🆙🚀 Flutter application upgrade/ Flutter App Upgrade /Flutter App Update/Flutter Update / download Plug-in

???? Flutter application upgrade/ Flutter App Upgrade /Flutter App Update/Flutter Update / download Plug-in (with notice bar progress), supports full upgrade, hot update and incremental upgrade

PengHui Li 344 Dec 30, 2022
ABC of Flutter widgets. Intended for super beginners at Flutter. Play with 35+ examples in DartPad directly and get familiar with various basic widgets in Flutter

Basic Widgets Examples This is aimed for complete beginners in Flutter, to get them acquainted with the various basic widgets in Flutter. Run this pro

Pooja Bhaumik 815 Jan 3, 2023
Minha primeira aplicação android utilizando Flutter feito no curso de Flutter da Cod3r Cursos Online. O foco dessa aplicação foi um contato inicial com o Flutter.

expenses Expenses é uma aplicação android simples feita em Flutter para controlar despesas pessoais. A aplicação consiste em: Listar transações feitas

Guilherme Teixeira Ais 2 Apr 19, 2022
Flutter Github Following Application, Using Flutter Provider and Flutter HTTP to get data from Github API.

Flutter Github Following Application Watch it on Youtube Previous Designs Checkout my Youtube channel Installation Please remember, after cloning this

Mohammad Rahmani 110 Dec 23, 2022
Flutter RSS feed parsing - A demo application of flutter which parse RSS XML contents to the flutter application

Flutter RSS feed parsing demo This is demo application of flutter which shows ho

Nyakuri Levite 3 Nov 15, 2022
Boris Gautier 1 Jan 31, 2022
Code for Flutter Talk from Flutter Vikings 2022: Custom User Interactions in Flutter

Custom User Interactions - Flutter Vikings 2022 A companion app for the Flutter Vikings 2022 talk - Custom User Interactions with Shortcuts, Intents,

Justin McCandless 9 Sep 16, 2022
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI 1/2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Fl

Johannes Milke 46 Dec 6, 2022
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI #2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flu

Johannes Milke 45 Dec 15, 2022
Let's create a selectable Flutter Navigation Drawer with routing that highlights the current item within the Flutter Sidebar Menu.

Flutter Tutorial - Sidebar Menu & Selectable Navigation Drawer Let's create a selectable Flutter Navigation Drawer with routing that highlights the cu

Johannes Milke 12 Dec 26, 2022
Components that optimize Flutter fluency.(Flutter 流畅度优化的通用方案,轻松解决卡顿问题)

Flutter fluency optimization component "Keframe" Page switching fluency improved: How to use Project depend on: Quick learning Constructor Description

Ke Technologies 793 Dec 30, 2022
Challenge yourself every weekend with flutter. Join me to implement challenging UI & digital designs using Flutter.

Weekend With Flutter This is my new challenge. Every weekend, I want to implement challenging UI & digital designs using Flutter. you can join me with

Payam Zahedi 16 Feb 24, 2022
Let's create a complete Flutter User Profile Page with SharedPreferences to persist the user's information in Flutter.

Flutter Tutorial - User Profile & SharedPreferences Let's create a complete Flutter User Profile Page with SharedPreferences to persist the user's inf

Johannes Milke 21 Dec 3, 2022
Let's create a Flutter Collapsible Sidebar Menu that can collapse and expand the Navigation Drawer in Flutter.

Flutter Tutorial - Collapsible Sidebar Menu & Navigation Drawer Let's create a Flutter Collapsible Sidebar Menu that can collapse and expand the Navig

Johannes Milke 22 Jan 3, 2023
🚗 Apple CarPlay for Flutter Apps. Aims to make it safe to use apps made with Flutter in the car by integrating with CarPlay.

CarPlay with Flutter ?? Flutter Apps now on Apple CarPlay! flutter_carplay aims to make it safe to use iPhone apps made with Flutter in the car by int

Oğuzhan Atalay 156 Dec 26, 2022
Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.

Flutter UI Boilerplate "Sharing for fun" Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file f

Dimas Ibnu Malik 122 Dec 1, 2022
This is a Flutter app which shows how to use the PageView Class in your Flutter App

page_view_class A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Shehzaan Mansuri 1 Oct 25, 2021