Flutter Cookbook

Book description

Discover how to build, scale, and debug native iOS and Android applications from a single codebase using the Dart programming language - a hands-on approach

Key Features

  • Work through practical recipes for building mobile applications with Flutter
  • Quickly build and iterate on your user interface (UI) with hot reload
  • Fix bugs and prevent them from reappearing using Flutter's developer tools and test suites

Book Description

"Anyone interested in developing Flutter applications for Android or iOS should have a copy of this book on their desk." - Amazon 5* Review

Lauded as the 'Flutter bible' for new and experienced mobile app developers, this recipe-based guide will teach you the best practices for robust app development, as well as how to solve cross-platform development issues.

From setting up and customizing your development environment to error handling and debugging, The Flutter Cookbook covers the how-tos as well as the principles behind them.

As you progress, the recipes in this book will get you up to speed with the main tasks involved in app development, such as user interface and user experience (UI/UX) design, API design, and creating animations. Later chapters will focus on routing, retrieving data from web services, and persisting data locally. A dedicated section also covers Firebase and its machine learning capabilities.

The last chapter is specifically designed to help you create apps for the web and desktop (Windows, Mac, and Linux).

Throughout the book, you'll also find recipes that cover the most important features needed to build a cross-platform application, along with insights into running a single codebase on different platforms.

By the end of this Flutter book, you'll be writing and delivering fully functional apps with confidence.

What you will learn

  • Use Dart programming to customize your Flutter applications
  • Discover how to develop and think like a Dart programmer
  • Leverage Firebase Machine Learning capabilities to create intelligent apps
  • Create reusable architecture that can be applied to any type of app
  • Use web services and persist data locally
  • Debug and solve problems before users can see them
  • Use asynchronous programming with Future and Stream
  • Manage the app state with Streams and the BLoC pattern

Who this book is for

If you're familiar with the basic concepts of programming and have your eyes set on developing mobile apps using Dart, then this book is for you. As a beginner, you'll benefit from the clear and concise step-by-step recipes, while a more experienced programmer will learn best practices and find useful tips. You'll get the most out of this book if you have experience coding in either JavaScript, Swift, Kotlin, Java, Objective-C, or C#.

Publisher resources

Download Example Code

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Flutter Cookbook
  3. Dedication
  4. Contributors
    1. About the authors
    2. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Sections
    8. Getting ready
    9. How to do it…
    10. How it works…
    11. There's more…
    12. See also
    13. Get in touch
    14. Reviews
  6. Getting Started with Flutter
    1. Technical requirements
    2. How to use Git to manage the Flutter SDK
    3. Installing Git 
    4. How to do it...
    5. See also
    6. Setting up the command line and saving path variables
    7. macOS command-line setup
    8. Windows command-line setup
    9. Confirming your environment is correct with Flutter Doctor
    10. Configuring the iOS SDK
    11. Downloading Xcode
    12. CocoaPods
    13. Xcode command-line tools
    14. Homebrew
    15. Checking in with the Doctor
    16. Configuring the Android SDK setup
    17. Installing Android Studio
    18. Creating an Android emulator
    19. Which IDE/editor should you choose?
    20. Android Studio
    21. VS Code
    22. IntelliJ IDEA
    23. Picking the right channel
    24. How to create a Flutter app
    25. How to do it...
    26. How to choose a platform language for your app
    27. Where do you place your code?
    28. Hot reload – refresh your app without recompiling
    29. Summary
  7. Dart: A Language You Already Know
    1. Technical requirements
    2. Declaring variables – var versus final versus const
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. See also
    8. Strings and string interpolation
    9. Getting ready
    10. How to do it...
    11. How it works...
    12. There's more...
    13. See also
    14. How to write functions
    15. Getting ready
    16. How to do it...
    17. How it works...
    18. How to use functions as variables with closures
    19. Getting ready
    20. How to do it...
    21. How it works...
    22. Creating classes and using the class constructor shorthand
    23. Getting ready
    24. How to do it...
    25. How it works...
    26. The building blocks of OOP
    27. See also
    28. How to group and manipulate data with collections
    29. Getting ready
    30. How to do it...
    31. How it works...
    32. Subscript syntax
    33. There's more...
    34. See also
    35. Writing less code with higher-order functions
    36. Getting ready
    37. How to do it...
    38. How it works...
    39. Mapping
    40. Sorting
    41. Filtering
    42. Reducing
    43. Flattening
    44. There's more...
    45. First-class functions
    46. Iterables and chaining higher-order functions
    47. See also
    48. How to take advantage of the cascade operator
    49. Getting ready
    50. How to do it...
    51. How it works...
    52. See also
    53. Understanding Dart Null Safety
    54. Getting ready
    55. How to do it...
    56. How it works...
    57. See also
  8. Introduction to Widgets
    1. Technical requirements
    2. Creating immutable widgets
    3. How to do it...
    4. How it works...
    5. Using a Scaffold
    6. Getting ready
    7. How to do it...
    8. How it works...
    9. Using the Container widget
    10. Getting ready
    11. How to do it...
    12. How it works...
    13. Printing stylish text on the screen
    14. Getting ready
    15. How to do it...
    16. How it works...
    17. There's more...
    18. See also
    19. Importing fonts and images into your app
    20. Getting ready
    21. How to do it...
    22. How it works...
    23. See also
  9. Mastering Layout and Taming the Widget Tree
    1. Placing widgets one after another
    2. Getting ready
    3. How to do it...
    4. How it works...
    5. Proportional spacing with the Flexible and Expanded widgets
    6. Getting ready
    7. How to do it...
    8. How it works...
    9. See also
    10. Drawing shapes with CustomPaint
    11. Getting ready
    12. How to do it...
    13. How it works...
    14. There's more...
    15. See also
    16. Nesting complex widget trees
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. See also
    21. Refactoring widget trees to improve legibility
    22. Getting ready
    23. How to do it...
    24. How it works...
    25. See also
    26. Applying global themes
    27. Getting ready
    28. How to do it...
    29. How it works...
    30. There's more...
    31. See also
  10. Adding Interactivity and Navigation to Your App
    1. Adding state to your app
    2. Getting ready
    3. How to do it...
    4. How it works...
    5. There's more...
    6. See also
    7. Interacting with buttons
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. Making it scroll
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. There's more...
    16. Handling large datasets with list builders
    17. How to do it...
    18. How it works...
    19. There's more...
    20. Working with TextFields
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. See also
    25. Navigating to the next screen
    26. How to do it...
    27. How it works...
    28. Invoking navigation routes by name
    29. How to do it...
    30. How it works...
    31. Showing dialogs on the screen
    32. How to do it...
    33. How it works...
    34. There's more...
    35. Presenting bottom sheets
    36. How to do it...
    37. How it works...
    38. See also
  11. Basic State Management
    1. Technical requirements
    2. Model-view separation
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. See also
    7. Managing the data layer with InheritedWidget
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. See also
    12. Making the app state visible across multiple screens
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. Designing an n-tier architecture, part 1 – controllers
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. See also
    21. Designing an n-tier architecture, part 2 – repositories
    22. Getting ready
    23. How to do it...
    24. How it works...
    25. Designing an n-tier architecture, part 3 – services
    26. How to do it...
    27. How it works...
    28. There's more...
    29. See also
  12. The Future is Now: Introduction to Asynchronous Programming
    1. Technical requirements
    2. Using a Future
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. See also
    7. Using async/await to remove callbacks
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. See also
    12. Completing Futures
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. There's more...
    17. See also
    18. Firing multiple Futures at the same time
    19. Getting ready
    20. How to do it...
    21. How it works...
    22. See also
    23. Resolving errors in asynchronous code           
    24. Getting ready
    25. How to do it...
    26. Dealing with errors using the then() callback:
    27. Dealing with errors using async/await
    28. How it works...
    29. See also
    30. Using Futures with StatefulWidgets
    31. Getting ready
    32. How to do it...
    33. How it works...
    34. There's more...
    35. See also
    36. Using the FutureBuilder to let Flutter manage your Futures
    37. Getting ready
    38. How to do it...
    39. How it works...
    40. There's more...
    41. See also
    42. Turning navigation routes into asynchronous functions
    43. Getting ready
    44. How to do it...
    45. How it works...
    46. Getting the results from a dialog      
    47. Getting ready
    48. How to do it...
    49. How it works...
    50. See also
  13. Data Persistence and Communicating with the Internet
    1. Technical requirements
    2. Converting Dart models into JSON
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. Reading the JSON file
    7. Transforming the JSON string into a list of Map objects
    8. Transforming the Map objects into Pizza objects
    9. There's more...
    10. See also
    11. Handling JSON schemas that are incompatible with your models
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. There's more...
    16. See also
    17. Catching common JSON errors
    18. Getting ready
    19. How to do it...
    20. How it works...
    21. See also
    22. Saving data simply with SharedPreferences
    23. Getting ready
    24. How to do it...
    25. How it works...
    26. See also
    27. Accessing the filesystem, part 1 – path_provider
    28. Getting ready
    29. How to do it...
    30. How it works...
    31. See also
    32. Accessing the filesystem, part 2 – working with directories
    33. Getting ready
    34. How to do it...
    35. How it works...
    36. See also
    37. Using secure storage to store data
    38. Getting ready
    39. How to do it...
    40. How it works...
    41. See also
    42. Designing an HTTP client and getting data
    43. Getting ready
    44. How to do it...
    45. How it works...
    46. There's more...
    47. See also
    48. POST-ing data
    49. Getting ready
    50. How to do it...
    51. How it works...
    52. PUT-ting data
    53. Getting ready
    54. How to do it...
    55. How it works...
    56. DELETE-ing data
    57. Getting ready
    58. How to do it...
    59. How it works...
  14. Advanced State Management with Streams
    1. Technical requirements
    2. How to use Dart streams 
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. There's more...
    7. See also
    8. Using stream controllers and sinks 
    9. Getting ready
    10. How to do it...
    11. How it works...
    12. There's more...
    13. See also
    14. Injecting data transform into streams 
    15. Getting ready
    16. How to do it...
    17. How it works...
    18. See also
    19. Subscribing to stream events
    20. Getting ready
    21. How to do it...
    22. How it works...
    23. See also
    24. Allowing multiple stream subscriptions
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. See also
    29. Using StreamBuilder to create reactive user interfaces
    30. Getting ready
    31. How to do it...
    32. How it works...
    33. See also
    34. Using the BLoC pattern 
    35. Getting ready
    36. How to do it...
    37. How it works...
    38. See also
  15. Using Flutter Packages
    1. Technical requirements
    2. Importing packages and dependencies
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. See also
    7. Creating your own package (part 1)
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. See also
    12. Creating your own package (part 2)
    13. Getting ready
    14. How to do it...
    15. How it works...
    16. See also
    17. Creating your own package (part 3)
    18. Getting ready
    19. How to do it...
    20. How it works...
    21. See also
    22. Adding Google Maps to your app
    23. Getting ready
    24. How to do it...
    25. How it works...
    26. See also
    27. Using location services
    28. Getting ready
    29. How to do it...
    30. How it works...
    31. See also
    32. Adding markers to a map
    33. Getting ready
    34. How to do it...
    35. How it works...
    36. There's more...
  16. Adding Animations to Your App
    1. Creating basic container animations
    2. Getting ready
    3. How to do it...
    4. How it works...
    5. See also
    6. Designing animations part 1 – using the AnimationController
    7. Getting ready
    8. How to do it...
    9. How it works...
    10. See also
    11. Designing animations part 2 – adding multiple animations
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. Designing animations part 3 – using curves
    16. Getting ready
    17. How to do it...
    18. How it works...
    19. See also
    20. Optimizing animations
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. See also
    25. Using Hero animations
    26. Getting ready
    27. How to do it...
    28. How it works...
    29. See also
    30. Using premade animation transitions
    31. Getting ready
    32. How to do it...
    33. How it works...
    34. See also
    35. Using the AnimatedList widget
    36. Getting ready
    37. How to do it...
    38. How it works...
    39. See also
    40. Implementing swiping with the Dismissible widget
    41. Getting ready
    42. How to do it...
    43. How it works...
    44. See also
    45. Using the animations Flutter package
    46. Getting ready
    47. How to do it...
    48. How it works...
    49. See also
  17. Using Firebase
    1. Configuring a Firebase app
    2. Getting ready
    3. How to do it...
    4. Android configuration
    5. iOS configuration
    6. Adding Firebase dependencies
    7. How it works...
    8. See also
    9. Creating a login form
    10. Getting ready
    11. How to do it...
    12. How it works...
    13. See also
    14. Adding Google Sign-in
    15. Getting ready
    16. How to do it...
    17. How it works...
    18. See also
    19. Integrating Firebase Analytics
    20. Getting ready
    21. How it works...
    22. How it works...
    23. See also
    24. Using Firebase Cloud Firestore 
    25. Getting ready
    26. How to do it...
    27. How it works...
    28. See also
    29. Sending Push Notifications with Firebase Cloud Messaging (FCM)
    30. Getting ready
    31. How to do it...
    32. How it works...
    33. See also
    34. Storing files in the cloud
    35. Getting ready
    36. How to do it...
    37. How it works...
  18. Machine Learning with Firebase ML Kit
    1. Using the device camera
    2. Getting ready
    3. How to do it...
    4. How it works...
    5. See also
    6. Recognizing text from an image
    7. Getting ready
    8. How to do it...
    9. How it works...
    10. See also
    11. Reading a barcode
    12. Getting ready
    13. How to do it...
    14. How it works...
    15. See also
    16. Image labeling
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. See also
    21. Building a face detector and detecting facial gestures
    22. Getting ready
    23. How to do it...
    24. How it works...
    25. See also
    26. Identifying a language
    27. Getting ready
    28. How to do it...
    29. How it works...
    30. See also
    31. Using TensorFlow Lite
    32. Getting ready
    33. How to do it...
    34. How it works...
    35. See also
  19. Distributing Your Mobile App
    1. Technical requirements
    2. Registering your iOS app on App Store Connect
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. See also
    7. Registering your Android app on Google Play
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. See also
    12. Installing and configuring fastlane
    13. Getting ready
    14. How to do it...
    15. Installing fastlane on Windows
    16. Installing fastlane on a Mac
    17. Configuring fastlane for Android
    18. Installing fastlane for iOS
    19. See also
    20. Generating iOS code signing certificates and provisioning profiles
    21. Getting ready
    22. How to do it...
    23. How it works...
    24. See also
    25. Generating Android release certificates
    26. Getting ready
    27. How to do it...
    28. How it works...
    29. See also
    30. Auto-incrementing your Android build number
    31. Getting ready
    32. How to do it...
    33. How it works...
    34. See also
    35. Configuring your app metadata
    36. Getting ready
    37. How to do it...
    38. Adding Android metadata
    39. Adding metadata for iOS
    40. How it works...
    41. See also
    42. Adding icons to your app
    43. Getting ready
    44. How to do it...
    45. How it works...
    46. See also
    47. Publishing a beta version of your app in the Google Play Store
    48. Getting ready
    49. How to do it...
    50. How it works...
    51. See also
    52. Using TestFlight to publish a beta version of your iOS app
    53. Getting ready
    54. How to do it...
    55. How it works...
    56. See also...
    57. Publishing your app to the stores
    58. Getting ready
    59. How to do it...
    60. Moving your app to production in the Play Store  
    61. Moving your app to production in the App Store
    62. How it works...
    63. See also...
  20. Flutter Web and Desktop
    1. Creating a responsive app leveraging Flutter Web
    2. Getting ready
    3. How to do it...
    4. How it works...
    5. See also...
    6. Running your app on macOS
    7. Getting ready
    8. How to do it...
    9. How it works...
    10. See also 
    11. Running your app on Windows
    12. Getting ready...
    13. How to do it...
    14. How it works...
    15. See also...
    16. Deploying a Flutter website
    17. Getting ready
    18. How to do it...
    19. How it works...
    20. See also...
    21. Responding to mouse events in Flutter Desktop
    22. Getting ready
    23. How to do it
    24. How it works...
    25. See also 
    26. Interacting with desktop menus
    27. Getting ready...
    28. How to do it...
    29. How it works...
    30. See also...
  21. About Packt
    1. Why subscribe?

Product information

  • Title: Flutter Cookbook
  • Author(s): Simone Alessandria, Brian Kayfitz
  • Release date: June 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781838823382