Flutter Cookbook - Second Edition

Book description

Write, test and publish your web, desktop, and embedded apps with this most up-to-date book on Flutter using the Dart programming language.

Key Features

  • Thoroughly updated to cover the latest features in Flutter 3.10.x and Dart 3.x
  • Practical recipes to publish responsive, multi-platform apps from a single database
  • Covers not just the ‘hows’ but the ‘whys’ of Flutter’s features with examples

Book Description

Are you ready to tap into the immense potential of Flutter?

With over 1,000 new mobile apps published every day on the Apple and Google Play stores, Flutter is transforming the landscape of app development. It's time for you to join the revolution.

Introducing the second edition of Flutter Cookbook, a step-by-step guide designed exclusively for you. Whether you're a seasoned developer or just starting your coding journey, this book is your ultimate companion. Dive into the latest features of Flutter 3.10 and unlock the secrets to building professional-grade, cross-platform applications.

With our recipe-based approach, we'll not only show you how to implement Flutter's features but also explain why they work. Through practical examples and real-world execution, you'll gain a deeper understanding of Flutter's inner workings. From crafting stunning UI/UX with widgets to leveraging hot reload and restart techniques, we'll equip you with best practices and invaluable knowledge.

As you progress, you'll learn to efficiently manage data, add interactivity and animations, and integrate essential Flutter plugins like maps, camera, voice recognition and more. And let's not forget the dedicated chapter on implementing MLkit powered by TensorFlow Lite. We'll guide you through building custom machine learning solutions, expanding the capabilities of your apps.

By the time you reach the end of this comprehensive Flutter book, you'll have the skills and confidence to write and deliver fully functional apps.

What you will learn

  • Familiarize yourself with Dart fundamentals and set up your development environment
  • Efficiently track and eliminate code errors with proper tools
  • Create various screens using multiple widgets to effectively manage data
  • Craft interactive and responsive apps by incorporating routing, page navigation, and input field text reading
  • Design and implement a reusable architecture suitable for any app
  • Maintain control of your codebase through automated testing and developer tooling
  • Develop engaging animations using the necessary tools
  • Enhance your apps with ML features using Firebase MLKit and TensorFlow Lite
  • Successfully publish your app on the Google Play Store and the Apple App Store

Who this book is for

Developers who are familiar with the OOP language and prefer learning-by-doing will get the most out of this book.

If you have some experience building apps on Flutter or have been playing around with the framework for some time now and have set eyes on developing mobile apps using Dart, then this book is for you.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Getting Started with Flutter
    1. Why Flutter?
    2. Technical requirements
    3. Installing Flutter: a high-level overview
    4. Installing the Flutter SDK
    5. How to use Git to manage the Flutter SDK
      1. Installing Git
      2. How to do it...
    6. Setting up the command line and saving path variables
      1. macOS command-line setup
      2. Windows command-line setup
      3. Linux command-line setup
    7. Confirming your environment is correct with Flutter Doctor
    8. Configuring the iOS SDK
      1. Downloading Xcode
      2. CocoaPods
      3. Xcode command-line tools
      4. Homebrew
      5. Checking in with the Doctor
    9. Configuring the Android SDK setup
      1. Installing Android Studio
      2. Creating an Android emulator
    10. Which IDE/editor should you choose?
      1. Android Studio
      2. VS Code
      3. IntelliJ IDEA
      4. Emacs
    11. Picking the right channel
    12. Summary
  3. Creating Your First Flutter App
    1. How to create a Flutter app
      1. How to do it...
      2. How to choose a platform language for your app
      3. Where do you place your code?
      4. Hot reload—refresh your app without recompiling
    2. Creating a unit test
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Summary
  4. Dart: A Language You Already Know
    1. Technical requirements
    2. Declaring variables—var versus final versus const
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    3. Strings and string interpolation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    4. How to write functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. How to use functions as variables with closures
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using Switch Expressions, Records and Patterns
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There’s more...
    7. Creating classes and using the class constructor shorthand
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. The building blocks of OOP
      4. See also
    8. How to group and manipulate data with collections
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Subscript syntax
      4. There’s more...
      5. See also
    9. Writing less code with higher-order functions
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Mapping
        2. Sorting
        3. Filtering
        4. Reducing
        5. Flattening
      4. There’s more...
        1. First-class functions
        2. Iterables and chaining higher-order functions
      5. See also
    10. How to take advantage of the cascade operator
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Using extensions
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Introducing Dart Null Safety
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    13. Using Null Safety in classes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    14. Summary
  5. Introduction to Widgets
    1. Technical requirements
    2. Creating immutable widgets
      1. How to do it...
      2. How it works...
    3. Using a Scaffold
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using the Container widget
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Printing stylish text on the screen
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    6. Importing fonts and images into your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Summary
  6. Mastering Layout and Taming the Widget Tree
    1. Placing widgets one after another
      1. Getting ready
      2. How to do it...
      3. How it works...
    2. Proportional spacing with the Flexible and Expanded widgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Drawing shapes with CustomPaint
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    4. Nesting complex widget trees
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Refactoring widget trees to improve legibility
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Applying global themes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    7. Summary
  7. Adding Interactivity and Navigation to Your App
    1. Adding state to your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    2. Interacting with buttons
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Making it scroll
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
    4. Handling large datasets with list builders
      1. How to do it...
      2. How it works...
      3. There’s more...
    5. Working with TextFields
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Navigating to the next screen
      1. How to do it...
      2. How it works...
    7. Showing dialogs on the screen
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
    8. Presenting bottom sheets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
      5. Summary
  8. Basic State Management
    1. Technical requirements
    2. Model-view separation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Managing the data layer with InheritedWidget and InheritedNotifier
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Making the app state visible across multiple screens
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Summary
  9. The Future is Now: Introduction to Asynchronous Programming
    1. Technical requirements
    2. Using a Future
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Using async/await to avoid callbacks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Completing Futures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    5. Firing multiple Futures at the same time
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Resolving errors in asynchronous code
      1. Getting ready
      2. How to do it...
        1. Dealing with errors using the then() callback:
        2. Dealing with errors using async/await
      3. How it works...
      4. See also
    7. Using Futures with StatefulWidgets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    8. Using the FutureBuilder to let Flutter manage your Futures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    9. Turning navigation routes into asynchronous functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Getting the results from a dialog
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Summary
  10. Data Persistence and Communicating with the Internet
    1. Technical requirements
    2. Converting Dart models into JSON
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Reading the JSON file
        2. Transforming the JSON string into a list of Map objects
        3. Transforming the Map objects into Pizza objects
      4. There’s more...
      5. See also
    3. Handling JSON schemas that are incompatible with your models
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Catching common JSON errors
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Saving data simply with SharedPreferences
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Accessing the filesystem, part 1: path_provider
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Accessing the filesystem, part 2: Working with directories
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Using secure storage to store data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Designing an HTTP client and getting data
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    10. POST-ing data
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. PUT-ting data
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. DELETE-ing data
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Advanced State Management with Streams
    1. Technical requirements
    2. How to use Dart streams
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    3. Using stream controllers and sinks
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
      5. See also
    4. Injecting data transforms into streams
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Subscribing to stream events
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Allowing multiple stream subscriptions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using StreamBuilder to create reactive user interfaces
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Using the BLoC pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Summary
  12. Using Flutter Packages
    1. Technical requirements
    2. Importing packages and dependencies
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Using dev dependencies
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Creating your own package (part 1)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Creating your own package (part 2)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Creating your own package (part 3)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Adding Google Maps to your app
      1. Getting ready
      2. How to do it...
        1. Adding Google Maps on Android
        2. Adding Google Maps on iOS
      3. How it works...
      4. See also
    8. Using location services
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Adding markers to a map
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There’s more...
    10. Summary
  13. Adding Animations to Your App
    1. Creating basic container animations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Designing animations part 1 — Using the AnimationController
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Designing animations part 2 — Adding multiple animations
      1. Getting ready
      2. How to do it…
      3. How it works...
    4. Designing animations part 3 — Using curves
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Optimizing animations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using Hero animations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using premade animation transitions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Using the AnimatedList widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Implementing swiping with the Dismissible widget
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Using the animations Flutter package
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Summary
  14. Using Firebase
    1. Configuring a Firebase app
      1. Getting ready
      2. How to do it...
        1. Adding Firebase dependencies
      3. How it works...
      4. See also
    2. Creating a login screen
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Adding Google Sign-in
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Customizing Sign in
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Integrating Firebase Analytics
      1. Getting ready
      2. How it works...
      3. How it works...
      4. See also
    6. Using Firebase Cloud Firestore
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Sending push notifications with Firebase Cloud Messaging (FCM)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Storing files in the cloud
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Summary
  15. Firebase Machine Learning
    1. Using the device’s camera
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    2. Recognizing text from an image
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Reading a barcode
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Image labeling
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Building a face detector and detecting facial gestures
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Identifying a language
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Using TensorFlow Lite
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Summary
  16. Flutter Web and Desktop
    1. Creating a responsive app leveraging Flutter Web
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    2. Running your app on macOS
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Running your app on Windows
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    4. Deploying a Flutter website
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    5. Responding to mouse events in Flutter Desktop
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. See also
    6. Interacting with desktop menus
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    7. Summary
  17. Distributing Your Mobile App
    1. Technical requirements
    2. Registering your iOS app on App Store Connect
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Registering your Android app on Google Play
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Installing and configuring fastlane
      1. Getting ready
      2. How to do it...
        1. Installing fastlane on Windows
        2. Installing fastlane on a Mac
        3. Configuring fastlane for Android
        4. Installing fastlane for iOS
      3. See also
    5. Generating iOS code signing certificates and provisioning profiles
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Generating Android release certificates
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Configuring your app metadata
      1. Getting ready
      2. How to do it...
        1. Adding Android metadata
        2. Adding metadata for iOS
      3. How it works...
      4. See also
    8. Adding icons to your app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    9. Publishing a beta version of your app in the Google Play Store
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    10. Using TestFlight to publish a beta version of your iOS app
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    11. Publishing your app to the stores
      1. Getting ready
      2. How to do it...
        1. Moving your app to production in the Play Store
        2. Moving your app to production in the App Store
      3. How it works...
      4. See also
    12. Summary
  18. Other Books You May Enjoy
  19. Index

Product information

  • Title: Flutter Cookbook - Second Edition
  • Author(s): Simone Alessandria
  • Release date: May 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803245430