Flutter and Dart Cookbook

Book description

Learn the essentials of working with Flutter and Dart to build full stack applications that meet the needs of a cloud-driven world. Together, the Flutter open source UI software development kit and the Dart programming language for client development provide a unified solution to building applications capable of targeting multiple platforms. Recipes in this cookbook show you how this potent combination provides an efficient approach to application development.

Typically used in frontend development, Flutter helps you develop cross-platform applications for Android, iOS, Linux, Mac, Windows, and the Google Fuchsia operating systems. The Dart SDK provides native access to third-party solutions, including APIs, databases, and authentication. When used in concert with Flutter, Dart allows you to compile source code ahead of time to native code.

This cookbook shows you how to:

  • Write effective Dart code by using variables and data structures
  • Build applications with Flutter by exploring widgets and data handling
  • Understand cloud provider solutions and learn how to integrate them with Flutter
  • Manage data through APIs using Google Cloud Serverless
  • Work with Firebase solutions such as Authentication and the Cloud Firestore database
  • Build web applications that also work with mobile and desktop platforms

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. Navigating This Book
    4. Conventions Used in This Book
    5. O’Reilly Online Learning
    6. How to Contact Us
    7. Acknowledgments
  3. 1. Learning Dart Variables
    1. 1.1. Running a Dart Application
    2. 1.2. Working with Integer Values
    3. 1.3. Working with Double Values
    4. 1.4. Working with Boolean Values
    5. 1.5. Working with Strings
    6. 1.6. Printing Information to the Console
    7. 1.7. Adding a Constant Variable (Compile Time)
    8. 1.8. Adding a Constant Variable (Runtime)
    9. 1.9. Working with Null Variables
  4. 2. Exploring Control Flow
    1. 2.1. Verifying That a Condition Has Been Met
    2. 2.2. Iterating Until a Condition Is Met
    3. 2.3. Iterating over a Range of Items
    4. 2.4. Performing Conditional Actions Based on a Value
    5. 2.5. Using an Enumerator to Represent Values
    6. 2.6. Implementing Exception Handling
  5. 3. Implementing Functions
    1. 3.1. Declaring Functions
    2. 3.2. Adding Parameters to Functions
    3. 3.3. Using Optional Parameters
    4. 3.4. Returning Values from Functions
    5. 3.5. Declaring Anonymous Functions
    6. 3.6. Adding a Functional Delay Using a Future
  6. 4. Handling Lists and Maps
    1. 4.1. Creating Lists of Data
    2. 4.2. Amending a List of Data
    3. 4.3. Using Lists with Complex Types
    4. 4.4. Handling Map Key/Value Pairings
    5. 4.5. Printing Map Data Structure Content
    6. 4.6. Validating That Content Exists in a Map
    7. 4.7. Printing Complex Data Types
  7. 5. Getting Started with Object-Oriented Dart
    1. 5.1. Beginning Object-Oriented Dart
    2. 5.2. Creating a Class
    3. 5.3. Initializing a Class Using a Constructor
    4. 5.4. Adding Class Inheritance
    5. 5.5. Adding a Class Interface
    6. 5.6. Adding a Class Mixin
  8. 6. Dart Test Cases
    1. 6.1. Adding the Dart Test Package to Your Application
    2. 6.2. Creating a Sample Test Application
    3. 6.3. Running Unit Tests in Your Dart Application
    4. 6.4. Grouping Multiple Unit Tests
    5. 6.5. Adding Mock Data for Testing
  9. 7. Introducing the Flutter Framework
    1. 7.1. Mocking an Application Interface
    2. 7.2. Creating a Boilerplate Flutter Project
    3. 7.3. Removing the Flutter Debug Banner
    4. 7.4. Recognizing Widgets
    5. 7.5. Understanding the Widget Tree
    6. 7.6. Improving Widget Render Performance
  10. 8. Adding Assets
    1. 8.1. Using the pubspec.yaml File
    2. 8.2. Adding an Assets Folder
    3. 8.3. Referencing an Image
    4. 8.4. Incorporating the Google Fonts Package
    5. 8.5. Importing a Package
  11. 9. Working with Widgets
    1. 9.1. Creating a Stateless Widget in Flutter
    2. 9.2. Creating a Stateful Widget in Flutter
    3. 9.3. Refactoring Flutter Widgets
    4. 9.4. Using the Scaffold Class
    5. 9.5. Adding an AppBar Header
    6. 9.6. Building with a Container
    7. 9.7. Using a Center Widget
    8. 9.8. Using a SizedBox
    9. 9.9. Using a Column
    10. 9.10. Using a Row
    11. 9.11. Using an Expanded Widget
  12. 10. Developing User Interfaces
    1. 10.1. Using the Google Fonts Package
    2. 10.2. Incorporating RichText
    3. 10.3. Identifying the Host Platform
    4. 10.4. Using a Placeholder Widget
    5. 10.5. Using a LayoutBuilder
    6. 10.6. Accessing Screen Dimensions Using MediaQuery
  13. 11. Organizing On-Screen Data
    1. 11.1. Implementing a Vertical ListView
    2. 11.2. Implementing a Horizontal ListView
    3. 11.3. Adding a SliverAppBar
    4. 11.4. Adding a SliverList
    5. 11.5. Adding a GridView of Items
    6. 11.6. Adding a SnackBar (Pop-Up Notification)
  14. 12. Flutter Page Navigation
    1. 12.1. Adding Page Navigation with Routes (Imperative)
    2. 12.2. Adding Page Navigation with Routes (Declarative)
    3. 12.3. Implementing a Navigation Drawer
    4. 12.4. Working with Tabs
    5. 12.5. Adding a Bottom Navigation Bar
    6. 12.6. Using Keys to Pass Information
  15. 13. Handling Data Assets
    1. 13.1. Accessing Data Strategically
    2. 13.2. Refactoring Data
    3. 13.3. Generating Dart Classes from JSON
    4. 13.4. Using Local JSON Data Asynchronously
    5. 13.5. Consuming a JSON Dataset from the Assets Folder
    6. 13.6. Accessing Remote JSON Data
  16. 14. Testing the Flutter User Interface
    1. 14.1. Automated Widget Testing in Flutter
    2. 14.2. Performing Automated Widget Testing
    3. 14.3. Performing Integration Testing with Flutter Driver
    4. 14.4. Testing Android/iOS Device Compatibility
  17. 15. Working with Firebase and Flutter
    1. 15.1. Using the Firebase Platform with Flutter
    2. 15.2. Setting Up a Firebase Project
    3. 15.3. Initializing the Firebase SDK for Local Development
    4. 15.4. Configuring Firebase Emulators
    5. 15.5. Adding flutterfire_cli to a Development Environment
    6. 15.6. Integrating a Firestore Database
    7. 15.7. Writing Data to a Firestore Database
    8. 15.8. Reading Data from Cloud Firestore
    9. 15.9. Adding Firebase Authentication to Flutter
    10. 15.10. Using Flutter Web with Firebase Hosting
  18. 16. Introducing Cloud Services
    1. 16.1. Getting Started with Cloud Providers
    2. 16.2. Working with Identity and Access Management
    3. 16.3. Using Cloud Storage to Host an Object
    4. 16.4. Developing a Backend HTTP Server with Dart
    5. 16.5. Building a Dart Container
    6. 16.6. Introducing Serverless with Dart
  19. 17. Starting with Game Development
    1. 17.1. Adding the Flame Package to Flutter
    2. 17.2. Creating a Flame Boilerplate
    3. 17.3. Adding a Sprite
    4. 17.4. Adding Manual Horizontal Movement to a Sprite
    5. 17.5. Adding Automated Vertical Movement to a Sprite
    6. 17.6. Adding Collision Detection
    7. 17.7. Adding Text Rendering
    8. 17.8. Adding Graphic Primitives
    9. 17.9. Adding Sound Effects
  20. Appendix. Setting Up Your Environment
    1. Determining Which Dart Installation to Use
    2. Running Dart in DartPad
    3. Installing the Flutter Framework
    4. Using Flutter Doctor
    5. Installing the Dart SDK
    6. Developing with VS Code
    7. Extending Android Studio to Support Dart
    8. Selecting a Release Channel
    9. Using Flutter Config to Set the Target Platform
  21. Index
  22. About the Author

Product information

  • Title: Flutter and Dart Cookbook
  • Author(s): Richard Rose
  • Release date: December 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098119515