100% found this document useful (1 vote)
31 views70 pages

Flutter Apprentice First Edition Learn To Build Crossplatform Apps 1st Edition Raywenderlich Tutorial Team Mike Katz Kevin David Moore Vincent Ngo Instant Download

The document is a promotional overview of the 'Flutter Apprentice First Edition' book, which teaches readers how to build cross-platform apps using Flutter. It includes links to various editions and related Flutter resources, along with a detailed table of contents outlining the chapters and topics covered in the book. The book emphasizes practical application development and includes sections on widgets, navigation, networking, and deployment.

Uploaded by

arsdesnindi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
31 views70 pages

Flutter Apprentice First Edition Learn To Build Crossplatform Apps 1st Edition Raywenderlich Tutorial Team Mike Katz Kevin David Moore Vincent Ngo Instant Download

The document is a promotional overview of the 'Flutter Apprentice First Edition' book, which teaches readers how to build cross-platform apps using Flutter. It includes links to various editions and related Flutter resources, along with a detailed table of contents outlining the chapters and topics covered in the book. The book emphasizes practical application development and includes sections on widgets, navigation, networking, and deployment.

Uploaded by

arsdesnindi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Flutter Apprentice First Edition Learn To Build

Crossplatform Apps 1st Edition Raywenderlich


Tutorial Team Mike Katz Kevin David Moore
Vincent Ngo download
https://ebookbell.com/product/flutter-apprentice-first-edition-
learn-to-build-crossplatform-apps-1st-edition-raywenderlich-
tutorial-team-mike-katz-kevin-david-moore-vincent-ngo-33001802

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Flutter Apprentice Learn To Build Crossplatform Apps 3rd Edition


Michael Katz

https://ebookbell.com/product/flutter-apprentice-learn-to-build-
crossplatform-apps-3rd-edition-michael-katz-46274842

Flutter Apprentice Fourth Edition Learn To Build Crossplatform Apps


4th Team

https://ebookbell.com/product/flutter-apprentice-fourth-edition-learn-
to-build-crossplatform-apps-4th-team-57307244

Flutter Apprentice Michael Katz Kevin David Moore Vincent Ngo Vincenzo
Guzzi

https://ebookbell.com/product/flutter-apprentice-michael-katz-kevin-
david-moore-vincent-ngo-vincenzo-guzzi-36137884

Flutter Dart Cookbook Fifth Early Release 1 20220916 Fifth Early


Release Richard Rose

https://ebookbell.com/product/flutter-dart-cookbook-fifth-early-
release-1-20220916-fifth-early-release-richard-rose-46247992
Flutter For Dummies Barry Burd

https://ebookbell.com/product/flutter-for-dummies-barry-burd-50195624

Flutter For Beginners An Introductory Guide To Building Crossplatform


Mobile Applications With Flutter 25 And Dart Second Edition 2nd
Edition Thomas Bailey

https://ebookbell.com/product/flutter-for-beginners-an-introductory-
guide-to-building-crossplatform-mobile-applications-with-
flutter-25-and-dart-second-edition-2nd-edition-thomas-bailey-52955604

Flutter Cookbook 100 Stepbystep Recipes For Building Crossplatform


Professionalgrade Apps With Flutter 310x Second Edition 2nd Edition
Simone Alessandria

https://ebookbell.com/product/flutter-cookbook-100-stepbystep-recipes-
for-building-crossplatform-professionalgrade-apps-with-
flutter-310x-second-edition-2nd-edition-simone-alessandria-52955612

Flutter Projects A Practical Projectbased Guide To Building Realworld


Crossplatform Mobile Applications And Games 1st Edition Simone
Alessandria

https://ebookbell.com/product/flutter-projects-a-practical-
projectbased-guide-to-building-realworld-crossplatform-mobile-
applications-and-games-1st-edition-simone-alessandria-52955630

Flutter For Beginners Crossplatform Mobile Development From Hello


World To App Release With Flutter 310 And Dart 3x Third Edition 3rd
Edition Thomas Bailey

https://ebookbell.com/product/flutter-for-beginners-crossplatform-
mobile-development-from-hello-world-to-app-release-with-
flutter-310-and-dart-3x-third-edition-3rd-edition-thomas-
bailey-53320462
Flutter Apprentice

Flutter Apprentice
By Michael Katz, Kevin David Moore & Vincent Ngo

Copyright ©2020 Razeware LLC.

Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without prior
written permission of the copyright owner.

Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.

Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.

raywenderlich.com 2
Flutter Apprentice

Table of Contents: Overview


Book License ............................................................................................. 13
Before You Begin ................................................................ 14
What You Need ........................................................................................ 15
Book Source Code & Forums ............................................................. 17
About the Cover ...................................................................................... 18
Acknowledgements ............................................................................... 23
Introduction .............................................................................................. 24
Section I: Build Your First Flutter App ......................... 27
Chapter 1: Getting Started ..................................................... 28
Chapter 2: Hello, Flutter .......................................................... 48
Section II: Everything’s a Widget .................................. 80
Chapter 3: Basic Widgets ........................................................ 81
Chapter 4: Understanding Widgets ................................. 125
Chapter 5: Scrollable Widgets ............................................ 152
Chapter 6: Interactive Widgets .......................................... 192
Section III: Navigating Between Screens ................. 261
Chapter 7: Routes & Navigation ........................................ 262
Chapter 8: Deep Links & Web URLs ................................. 315
Section IV: Networking, Persistence and State ..... 351
Chapter 9: Shared Preferences .......................................... 352
Chapter 10: Serialization With JSON .............................. 369

raywenderlich.com 3
Flutter Apprentice

Chapter 11: Networking in Flutter ................................... 384


Chapter 12: Using the Chopper Library.......................... 401
Chapter 13: State Management......................................... 417
Chapter 14: Streams ............................................................... 455
Chapter 15: Saving Data With SQLite ............................. 473
Section V: Deployment .................................................. 519
Chapter 16: Platform Specific App Assets ..................... 520
Chapter 17: Build & Release an Android App ............... 540
Chapter 18: Build & Release an iOS App ........................ 568
Conclusion .............................................................................................. 593
Appendices ........................................................................ 594
Appendix A: Chapter 5 Solution 1 ..................................... 595
Appendix B: Chapter 5 Solution 2 ..................................... 597

raywenderlich.com 4
Flutter Apprentice

Table of Contents: Extended


Book License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
What You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Book Source Code & Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
About the Cover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
About the Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
About the Artist. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Content Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
How to read this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Section I: Build Your First Flutter App. . . . . . . . . . . . . . 27


Chapter 1: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
What is Flutter? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Flutter’s history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The Flutter architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
What’s ahead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Getting the Flutter SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Trying it out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Chapter 2: Hello, Flutter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Creating a new app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

raywenderlich.com 5
Flutter Apprentice

Making the app yours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51


Clearing the app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Building a recipe list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Adding a recipe detail page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Section II: Everything’s a Widget . . . . . . . . . . . . . . . . . . . 80


Chapter 3: Basic Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Styling your app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Setting a theme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
App structure and navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Creating custom recipe cards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Chapter 4: Understanding Widgets . . . . . . . . . . . . . . . . . . . . . . . . 125
What is a widget? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Unboxing Card2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Rendering widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Types of widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Chapter 5: Scrollable Widgets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Introducing ListView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Setting up ExploreScreen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Creating a FutureBuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Building Recipes of the Day . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Nested ListViews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

raywenderlich.com 6
Flutter Apprentice

Creating FriendPostListView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174


Adding final touches for ExploreScreen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Getting to Know GridView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Building the Recipes screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Other scrollable widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Chapter 6: Interactive Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Creating the grocery item model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Creating the Grocery screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Creating the empty Grocery screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Switching tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Managing tab state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Managing the grocery items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Adding new packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Creating GroceryItemScreen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Creating GroceryTile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Building GroceryTile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Finishing GroceryTile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Saving the user’s work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Creating GroceryListScreen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Adding gestures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Dismissing items with a swipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

Section III: Navigating Between Screens . . . . . . . . . 261


Chapter 7: Routes & Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Introducing Navigator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

raywenderlich.com 7
Flutter Apprentice

Navigator 1.0 overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264


Navigator 1.0’s disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Navigator 2.0 overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Navigation and unidirectional data flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Is Navigator 2.0 always better than Navigator 1.0? . . . . . . . . . . . . . . . . . 271
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Changes to the project files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Looking over the UI flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Managing your app state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Creating the router . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Using your app router . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Adding screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Showing the Splash screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Displaying the Login screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Transitioning from Login to Onboarding screen. . . . . . . . . . . . . . . . . . . . . 296
Transitioning from Onboarding to Home . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Handling tab selection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Showing the Grocery Item screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Navigating to the Profile screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Navigating to raywenderlich.com . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Logging out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Handling the Android system’s Back button . . . . . . . . . . . . . . . . . . . . . . . . 311
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Chapter 8: Deep Links & Web URLs . . . . . . . . . . . . . . . . . . . . . . . . 315
Understanding deep links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Overview of Fooderlich’s paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Recapping Navigator 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Deep links under the hood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Creating a navigation state object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327

raywenderlich.com 8
Flutter Apprentice

Creating a route information parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330


Connecting the parser to the app router . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Converting a URL to an app state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Converting the app state to a URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Testing deep links. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Running the web app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350

Section IV: Networking, Persistence and State . . . 351


Chapter 9: Shared Preferences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Saving data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
The shared_preferences plugin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Chapter 10: Serialization With JSON . . . . . . . . . . . . . . . . . . . . . . 369
What is JSON? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Automating JSON serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Creating model classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Chapter 11: Networking in Flutter . . . . . . . . . . . . . . . . . . . . . . . . . 384
Signing up with the recipe API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Using the HTTP package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Connecting to the recipe service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Building the user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Chapter 12: Using the Chopper Library . . . . . . . . . . . . . . . . . . . . 401

raywenderlich.com 9
Flutter Apprentice

Why Chopper?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402


Preparing to use Chopper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Preparing the recipe service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Converting request and response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Encoding and decoding JSON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Using interceptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Generating the Chopper file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Logging requests & responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Using the Chopper client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Chapter 13: State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Why you need state management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Widget state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Application state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Managing state in your app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Using Provider. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
UI Models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Creating the recipe class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Convert data into models to display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Creating a repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Creating a memory repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Using a mock service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Other state management libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Chapter 14: Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Types of streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Adding streams to Recipe Finder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Sending recipes over the stream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

raywenderlich.com 10
Flutter Apprentice

Exercise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Switching between services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Adding streams to Bookmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Adding streams to Groceries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Chapter 15: Saving Data With SQLite . . . . . . . . . . . . . . . . . . . . . . 473
Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Adding a database to the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Adding an SQLite repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Running the app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Using Moor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518

Section V: Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . 519


Chapter 16: Platform Specific App Assets. . . . . . . . . . . . . . . . . . 520
Setting the app icon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Setting the app’s name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Adding a launch screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Chapter 17: Build & Release an Android App . . . . . . . . . . . . . . 540
Set up for release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Build an app bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
Uploading to the Google Play Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Uploading a build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567

raywenderlich.com 11
Flutter Apprentice

Chapter 18: Build & Release an iOS App . . . . . . . . . . . . . . . . . . . 568


Creating the signing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Setting up the App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Uploading to the App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Sharing builds through TestFlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Where to go from here? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
Appendix A: Chapter 5 Solution 1 . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Appendix B: Chapter 5 Solution 2 . . . . . . . . . . . . . . . . . . . . . . . . . . 597

raywenderlich.com 12
L Book License

By purchasing Flutter Apprentice, you have the following license:

• You are allowed to use and/or modify the source code in Flutter Apprentice in as
many apps as you want, with no attribution required.

• You are allowed to use and/or modify all art, images and designs that are included
in Flutter Apprentice in as many apps as you want, but must include this attribution
line somewhere inside your app: “Artwork/images/designs: from Flutter Apprentice,
available at www.raywenderlich.com”.

• The source code included in Flutter Apprentice is for your personal use only. You
are NOT allowed to distribute or sell the source code in Flutter Apprentice without
prior authorization.

• This book is for your personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, coworkers or students; they
would need to purchase their own copies.

All materials provided with this book are provided on an “as is” basis, without
warranty of any kind, express or implied, including but not limited to the warranties
of merchantability, fitness for a particular purpose and noninfringement. In no event
shall the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising from, out of or in
connection with the software or the use or other dealings in the software.

All trademarks and registered trademarks appearing in this guide are the properties
of their respective owners.

raywenderlich.com 13
Before You Begin

This section tells you a few things you need to know before you get started, such as
what you’ll need for hardware and software, where to find the project files for this
book, and more.

raywenderlich.com 14
i What You Need

To follow along with this book, you’ll need the following:

• Xcode 12.4 or later. Xcode is iOS’s main development tool, so you need it to build
your Flutter app for iOS. You can download the latest version of Xcode from
Apple’s developer site here: apple.co/2asi58y or from the Mac App Store. Xcode
12.4 requires a Mac running macOS Catalina (10.15) or later.

Note: You also have the option of using Linux or Windows, but you won’t be
able to install Xcode or build apps for iOS on those platforms.

Note: Starting in April 2021, Apple requires apps submitted to the App Store
to be developed using macOS Catalina (10.15) or later with the iOS 14
SDK.

• Cocoapods 1.10.1 or later. Cocoapods is a dependency manager Flutter uses to


run code on iOS.

• Flutter SDK 2.2.0 or later. You can download the Flutter SDK from the official
Flutter site at https://flutter.dev/docs/get-started/install/macos. Installing the
Flutter SDK will also install the Dart SDK, which you need to compile the Dart
code in your Flutter apps.

raywenderlich.com 15
Flutter Apprentice What You Need

• Android Studio 4.2.1 or later, available at https://developer.android.com/studio.


This is the IDE in which you’ll develop the sample code in this book. It also
includes the Android SDK and the build system for running Flutter apps on
Android.

• Flutter Plugin for Android Studio 56.0.2 or later, installed by going to Android
Studio Preferences on macOS (or Settings on Windows/Linux) and choosing
Plugins, then searching for “Flutter”.

You have the option of using Visual Studio Code for your Flutter development
environment instead of Android Studio. You’ll still need to install Android Studio to
have access to the Android SDK and an Android emulator. If you choose to use Visual
Studio Code, follow the instructions on the official Flutter site at https://flutter.dev/
docs/get-started/editor?tab=vscode to get set up.

Chapter 1, “Getting Started“ explains more about Flutter history and architecture.
You’ll learn how to start using the Flutter SDK, then you’ll see how to use Android
Studio and Xcode to build and run Flutter apps.

Note about null safety: At the time of publication, some of the dependencies
used throughout the book do not fully support null safety, so the code you’ll
see from Chapter 3, “Basic Widgets” on is not null safe. We’ll migrate the code
to support non-nullable types in a future update to this book.

raywenderlich.com 16
ii Book Source Code &
Forums

Book source code


The materials for this book are all available in the GitHub repository here:

• https://github.com/raywenderlich/flta-materials

You can download the entire set of materials for the book from that page.

Forum
We’ve also set up an official forum for the book at https://forums.raywenderlich.com/
c/books/flutter-apprentice/. This is a great place to ask questions about the book or
to submit any errors you may find.

raywenderlich.com 17
iii About the Cover

Flutter Apprentice Cover


While Flutter’s official mascot is the hummingbird — meant to represent the speed of
the Dart language and the swiftness of building apps with the Flutter framework – we
were drawn to the expressive and transformative elegance of the monarch butterfly
(Danaus plexippus) for our cover.

In cultures all over the world for thousands of years, butterflies have been seen as a
symbol of mysterious transformation: The caterpillar wraps itself in silk and emerges
with wings, its original simple form now completely native to the body of a butterfly.

That’s also the magical power of Flutter — wrap your project in the framework’s
widgets and out comes something that appears endemic to iOS or Android
ecosystems from the same codebase.

raywenderlich.com 18
Flutter Apprentice About the Cover

The monarch butterfly is, of course, most famously known for its unfathomable
North American migration from Canada and the Northern United States to Mexico.
Fluttering for thousands of miles at just 5.5 miles/hour (8.85 km/hour for our global
friends), it isn’t just one butterfly making the journey at all. It takes three
generations of monarchs to make the complete migration: Those born in spring and
early summer live just 28-32 days, and those born in late summer live up to 8 months
to return home.

Luckily, your own journey will not be so long or perilous! We hope that our book
gives you all the tools you need to migrate your own projects with ease and help you
make beautiful apps that take flight.

raywenderlich.com 19
Flutter Apprentice Dedications

“To my wife and family for putting up with me for always


being on the computer and letting me create and learn.”

— Kevin David Moore

“To my loving parents and sister. Thank you for always being
there for me, especially during the hard times. To Ray and the
entire RW team who started me on this journey, I am beyond
grateful to be part of this family. To the Flutter community,
without whom I would have nothing to create and share here.”

— Vincent Ngo

“To my children for providing encouragement and giving me


just enough time to write.”

— Michael Katz

raywenderlich.com 20
Flutter Apprentice Dedications

About the Authors


Michael Katz is champion baker. He’s also a developer, architect,
speaker, writer and avid homebrewer. He has contributed to several
books on iOS development and is a long-time member of the
https://raywenderlich.com/ tutorial team. He shares his home state
of New York with his family, the world’s best bagels, and the
Yankees. When not at his computer, he’s out on the trails, in his
shop, or reading a good book (like this one!).

Kevin David Moore is an author of this book. Kevin has been


developing Android apps for over 10 years and at many companies.
He’s written several articles at https://raywenderlich.com/ and
created the “Programming in Kotlin” video series. He enjoys
creating apps for fun and teaching others how to write Android
apps. In addition to programming, he loves playing volleyball and
running the sound system at church.

Vincent Ngo is an author of this book. A software developer by day


at a growing startup, and a Flutter enthusiast by night, he believes
that sharing knowledge is the best way to learn and grow as a
techie. Vincent starts every morning with a Cà phê sữa đá
(Vietnamese coffee) to fuel his day. He enjoys playing in small golf
tournaments, meditating, and watching animated movies. You can
find him on Twitter: https://twitter.com/vincentngo2.

About the Editors


Stephanie Patterson is a tech editor for this book. Stef is
passionate about helping others learn, which includes mentoring,
writing and editing documentation, data wrangling and coding by
example. Throughout most of her career, she worked as a senior
SQL developer and analyst. In 2013, she started creating iOS apps
using raywenderlich.com books and articles. Now, thanks to
Flutter, Stef is creating natively compiled cross-platform apps. Stef
loves movies, trivia nights, Sci-Fi and spending time with her
husband, daughter and their chiweenie, Gracie. You can find her on
Twitter at https://twitter.com/geekmespeakstef.

raywenderlich.com 21
Flutter Apprentice Dedications

Sandra Grauschopf is the editor of this book. She is a freelance


writer, editor, and content strategist as well as the Editing Team
Lead at https://raywenderlich.com/. She loves to untangle tortured
sentences and to travel the world with a trusty book in her hand.

Cesare Rocchi is the final pass editor for this book. Cesare runs
https://studiomagnolia.com, an interactive studio that creates
compelling web and mobile applications. He blogs at https://
www.upbeat.it. You can find him on Twitter at https://twitter.com/
_funkyboy.

About the Artist


Vicki Wenderlich is the designer and artist of the cover of this
book. She is Ray’s wife and business partner. She is a digital artist
who creates illustrations, game art and a lot of other art or design
work for the tutorials and books on raywenderlich.com. When she’s
not making art, she loves hiking, a good glass of wine and
attempting to create the perfect cheese plate.

raywenderlich.com 22
vi Acknowledgements

Content Development
We would like to thank Tim Sneath and Chris Sells from Google. Both provided key
insights and constant encouragement during the gestation and development of this
book.

We would also like to thank Joe Howard for his work as an FPE for the book in its
early stages. Joe’s path to software development began in the fields of computational
physics and systems engineering. He started as a web developer and also has been a
native mobile developer on iOS and Android since 2009. Joe has a passion for system
and enterprise architecture including building robust, testable, maintainable, and
scalable systems. He currently focuses on the full stack using web frameworks like
React and Angular, Node.js microservices, GraphQL, and devops tools like Docker,
Kubernetes, and Terraform. He lives in Boston and is a Senior Architect at CVS
Health.

raywenderlich.com 23
vii Introduction

Welcome to Flutter Apprentice!

Flutter is an incredible user interface (UI) toolkit that lets you build apps for iOS and
Android — and even the web and desktop platforms like macOS, Windows and Linux
— all from a single codebase.

Flutter has all the benefits of other cross-platform tools, especially because you’re
targeting multiple platforms from one codebase. Furthermore, it improves upon
most cross-platform tools thanks to a super-fast rendering engine that makes your
Flutter apps perform nearly, or even exactly, the same as native apps.

In addition, Flutter features are generally independent of native features, since you
use Flutter’s own type of UI elements, called widgets, to create your UI. And Flutter
has the ability to work with native code, so you can integrate your Flutter app with
native features when you need to.

If you’re coming from a platform like iOS or Android, you’ll find the Flutter
development experience refreshing! Thanks to a feature called “hot reload”, you
rarely need to rebuild your apps as you develop them. A running app in a simulator
or emulator will refresh with code changes automatically as you save your source
files!

In this book, you’ll see how to build full-featured Flutter apps, gain experience with a
wide range of Flutter widgets and learn how to deploy your apps to mobile app
stores.

raywenderlich.com 24
Flutter Apprentice Introduction

How to read this book


In the first section of the book, you’ll learn how to set up a Flutter development
environment. Once that’s done, you’ll start building your first Flutter app.

The next two sections focus on UI development with Flutter widgets. You’ll see just
how impressive Flutter user interfaces can be.

The fourth section switches to building a new app. You’ll use it to learn about using
networking and databases with Flutter, as well as the all-important topic of state
management.

The book’s final section shows you how to incorporate platform-specific assets into
your app, then demonstrate how to deploy your apps to the mobile app stores.

Here’s a breakdown of these five main sections of the book:

Section I: Build Your First Flutter App


The chapters in this section introduce you to Flutter, get you up and running with a
Flutter development environment and walk you through building your first Flutter
app.

You’ll learn about where Flutter came from and why it exists, understand the
structure of Flutter projects and see how to create the UI of a Flutter app.

You’ll also get your first introduction to the key component found in Flutter user
interfaces: widgets!

Section II: Everything’s a Widget


In this section, you’ll start to build a full-featured recipe app named Fooderlich.
You’ll gain an understanding the wide range of widgets available in Flutter and put
them to use. Then you’ll learn the theory of how widgets work behind the scenes.

Finally, you’ll dive deeper into layout widgets, scrollable widgets and interactive
widgets.

raywenderlich.com 25
Flutter Apprentice Introduction

Section III: Navigating Between Screens


You’ll continue working on the Fooderlich app in this section, learning about
navigating between screens and working with deep links.

Topics you’ll learn include Navigator 2.0 and Flutter Web.

Section IV: Networking, Persistence & State


Most apps interact with the network to retrieve data and then persist that data
locally in some form of cache, such as a database. In this section, you’ll build a new
app that lets you search the Internet for recipes, bookmark recipes and save their
ingredients into a shopping list.

You’ll learn about making network requests, parsing the network JSON response and
saving data in a SQLite database. You’ll also get an introduction to using Dart
streams.

Finally, this section will dive deeper into the important topic of app state, which
determines where and how to refresh data in the UI as a user interacts with your app.

Section V: Deployment
Building an app for you own devices is great; sharing your app with the world is even
better!

In this section, you’ll go over the steps and processes to release your apps to the iOS
App Store and Google Play Store. You’ll also see how to use platform-specific assets
in your apps.

raywenderlich.com 26
Section I: Build Your First
Flutter App

The chapters in this section will introduce you to Flutter, get you up and running
with a Flutter development environment and walk you through building your first
Flutter app.

You’ll learn about where Flutter came from and why it exists, understand the
structure of Flutter projects, and see how to create the user interface of a Flutter app.

You’ll also get your first introduction to the key component found in Flutter user
interfaces: Widgets!

raywenderlich.com 27
1 Chapter 1: Getting Started
By Michael Katz

Congratulations. By opening “The Flutter Apprentice”, you’ve taken your first step
toward becoming a Flutter master. This book will be your guide to learning the
Flutter UI Toolkit, Google’s platform for building apps for mobile, desktop and web
from a single codebase.

The five sections of this book will progressively teach you how to create an app using
Flutter. You’ll learn all about widgets, which are components that you compose to
build your apps. You’ll also learn about navigation and transitions, handling state
and network management. Finally, you’ll learn how to deploy the app to testers and
users.

This book assumes you’re familiar with development for a native mobile platform,
such as iOS with Swift or Android with Kotlin… but you don’t need to be an expert by
any means. These chapters will show you how to build a Flutter app from scratch, so
if you’re completely new, you’ll catch up just fine.

raywenderlich.com 28
Flutter Apprentice Chapter 1: Getting Started

What is Flutter?
In the simplest terms, Flutter is a software development toolkit from Google for
building cross-platform apps. Flutter apps consist of a series of packages, plugins and
widgets — but that’s not all. Flutter is a process, a philosophy and a community as
well.

It’s also the easiest way to get an app up and running on any one platform, let alone
multiple. You can be more productive than you thought possible thanks to Flutter’s
declarative, widget-based UI structure, first-class support for reactive programming,
cross platform abstractions and its virtual machine that allows for hot reloading of
code changes.

One thing Flutter is not is a language. Flutter uses Dart as its programming
language. If you know Kotlin, Swift, Java or Typescript, you’ll find Dart familiar, since
it’s an object-oriented C-style language.

You can compile Dart to native code, which makes it fast. It also uses a virtual
machine (VM) with a special feature: hot reload. This lets you update your code and
see the changes live without redeploying it.

For years, programmers have been promised the ability to write once and run
anywhere; Flutter may well be the best attempt yet at achieving that goal.

Seriously?
Yes, Flutter is that awesome. You can build a high-quality app that’s performant and
looks great, very quickly. This book will show you how.

In the first few chapters, you’ll get your feet under you with the basic UI. By the end
of the book, you’ll be able to build apps that look great and perform well.

And it truly does work well with both desktop and web.

raywenderlich.com 29
Flutter Apprentice Chapter 1: Getting Started

Other cross-platform toolkits have tried to abstract the underlying OS by adding a


layer on top of the native UI layer. This leaves the developer with the lowest common
set of features available — not to mention, degraded performance.

In contrast, Flutter’s widgets exist parallel to native widgets due to its custom user
interface rendering engine, Skia. That means that the toolkit controls how the UI
looks and behaves, which allows for consistent behavior between platforms. From a
performance perspective, there’s no penalty from additional layers of abstraction.

Who’s Flutter for?

Flutter is for both the new or experienced developer who wants to start a mobile app
with minimal overhead. Flutter is for someone looking to make an app that runs on
multiple devices, either right away or in the future. It’s for someone who prefers to
build declarative UIs with the support of a large, open-source community.

Additionally, Flutter is for developers with experience on one platform who want to
develop an app that works across many. This is doubly true if you’re a web developer
with deep Javascript or Typescript knowledge, but haven’t gotten started on mobile
yet. You can learn both major mobile platforms at once!

If you don’t have an existing app, Flutter is a great way to develop something quickly
to validate an idea or to build a full, multi-platform production app.

On the other hand, if you already have a great app on one platform with the native
toolkits, then you should evaluate your ongoing maintenance costs to see if it makes
sense to build out for the other platforms by using Flutter or the native toolkits.

raywenderlich.com 30
Flutter Apprentice Chapter 1: Getting Started

Great things about Flutter


Here’s just a sample of some of the great things about using Flutter:

• Flutter is open-source. That means you can watch its evolution and know what’s
coming — and even try out new features in development. You can also create your
own patches and packages or contribute code. And you can be involved in the
community to help others or contribute to its future direction.

• Flutter uses the Dart programming language. Dart (https://dart.dev) is a modern,


UI-focused language that’s compiled to native ARM or x86 code or cross-compiled
to Javascript. It supports all the great language features people have come to like
and expect, such as async/await for concurrency management and type
inference for clean, type-safe code.

• One of the best features of Flutter is hot reload. Hot reload allows you to make
updates to the code and the UI that rebuild the widget tree, then deliver them live
to emulators and devices — without having to reload state or recompile your app.

• Sometimes, you make changes that affect too much of the widget tree or app state
to hot reload easily. In those cases, you can use hot restart. Hot restart takes a
little longer than hot reload because it loads the changes, restarts the app and
resets the state, but it’s still faster than a full restart, which recompiles and
redeploys. You need to use a full restart when you make certain significant changes
to the code, including anything changing state management.

• These restart features leverage Dart’s VM to inject the updated code, so they’re
only available in debug mode and not in a production app.

• Other cross-platform toolkits produce apps with a stock look and feel — boring!
Flutter is purposely attractive, using Google’s Material Design out of the box. It’s
also easy to apply Cupertino widgets to get an iOS-like appearance. The UI is fully
customizable, allowing you make an app that looks right for your brand.

• Flutter comes with great animations and transitions, and you can build custom
widgets as well. Because widgets are composable, you can be creative and flexible
with the UI. For example, you can put videos behind a scroll view or put a toolbar
on top of a canvas.

• The sheer number of widgets and the declarative syntax for building UIs lets you
be extremely productive, building a rich app quickly with minimal overhead and
boilerplate. Stateful widgets are bound to data and automatically update as the
data model changes.

raywenderlich.com 31
Flutter Apprentice Chapter 1: Getting Started

• If you’ve used SwiftUI or Jetpack Compose recently, you’re already familiar with
many of Flutter’s concepts. But Flutter is even better — it has fewer limitations on
the tools and you can build for multiple platforms at once.

• Flutter was designed with accessibility in mind, with out-of-the-box support for
dynamic font sizes and screen readers and a ton of best practices around language,
contrast and interaction methods.

• Platform integration is important for accessing libraries written in other languages


or using platform-specific features that don’t have a Flutter support package yet.
Flutter supports C and C++ interoperability as well as platform channels for
connecting to Kotlin and Java on Android and Swift or Objective-C on iOS.

Are you convinced yet?


If you’re not yet convinced that there’s a place for Flutter, check out the showcase:
https://flutter.dev/showcase.

There, you see the top companies using Flutter and how diverse the apps you can
make with it are. These aren’t limited to “JSON-in-a-table” apps, but also include
media-rich dynamic and interactive apps.

These apps help you be more productive, better informed, communicate more easily
and have more fun. Flutter’s native performance and system integrations make it a
better choice than a web or hybrid app for most mobile applications.

Popular apps from some of the world’s biggest companies are built with Flutter.
These include:

• Very Good Ventures

• Tencent

• Realtor.com

• Google Assistant

• New York Times

• Policygenius

• Google Stadia

raywenderlich.com 32
Flutter Apprentice Chapter 1: Getting Started

Take a look at some recent examples:

When not to use Flutter


Flutter isn’t the best tool for every application. Here are some areas where Flutter is
an evolving platform.

Games and audio

While you can create simple 2D games using Flutter, for complex 2D and 3D games,
you’d probably prefer to base your app on a cross-platform game engine technology
like Unity or Unreal. They have more domain-specific features like physics, sprite and
asset management, game state management, multiplayer support and so on.

Flutter doesn’t have a sophisticated audio engine yet, so audio editing or mixing
apps are at a disadvantage over those that are purpose-built for a specific platform.

Apps with specific native SDK needs

Flutter supports many, but not all, native features. Fortunately, you can usually
create bridges to platform-specific code. However, if the app is highly integrated with
a device’s features and platform SDKs, it might be worth writing the app using the
platform-specific tools. Flutter also produces app binaries that are bigger in size than
those built with platform frameworks.

raywenderlich.com 33
Flutter Apprentice Chapter 1: Getting Started

Flutter might not be a practical choice if you are only interested in a single platform
app and you have deep knowledge of that platform’s tools and languages. For
example, if you’re working with a highly-customized iOS app based on CloudKit that
uses all the native hardware, MLKit, StoreKit, extensions and so on, maintaining and
taking advantage of those features will be easier using SwiftUI. Of course, the same
goes for a heavily-biased Android app using Jetpack Compose.

Certain platforms

Flutter doesn’t run everywhere. It doesn’t support Apple Bitcode yet, which means
that it doesn’t support watchOS, tvOS or certain iOS app extensions. Its support for
the web is still in its early days, which means that Flutter has many features and
performance improvements ahead of it — but they’re coming.

Since Flutter doesn’t run on watches or TVs yet, you’ll have to build those
components natively and attach them to a Flutter-based mobile app. Depending on
how sophisticated those other apps are, it might not be worth the hassle to write
both native and Flutter code.

Flutter’s history
Flutter comes from a tradition of trying to improve web performance. It’s built on top
of several open-source technologies developed at Google to bring native
performance and modern programming to the web through Chrome.

The Flutter team chose the Dart language, which Google also developed, for its
productivity enhancements. Its object-oriented type system and support for reactive
and asynchronous programming gives it clear advantages over Javascript. Most
importantly, Google built the Dart VM into the Chrome browser, allowing web apps
written in Dart to run at native speeds.

Another piece of the puzzle is the inclusion of Skia as the graphics rendering layer.
Skia is a another Google-based open source project that powers the graphics on
Android, Chrome browsers, Chrome OS and Firefox. It runs directly on the GPU using
Vulcan on Android and Metal on iOS, making the graphics layer fast on mobile
devices. Its API allows Flutter widgets to render quickly and consistently, regardless
of its host platform.

raywenderlich.com 34
Flutter Apprentice Chapter 1: Getting Started

The Flutter architecture


Flutter has a modular, layered architecture. This allows you to write your application
logic once and have consistent behavior across platforms, even though the
underlying engine code differs depending on the platform. The layered architecture
also exposes different points for customization and overriding, as necessary.

The Flutter architecture consists of three main layers:

1. The Framework layer is written in Dart and contains the high-level libraries that
you’ll use directly to build apps. This includes the UI theme, widgets, layout and
animations, gestures and foundational building blocks. Alongside the main
Flutter framework are plugins: high-level features like JSON serialization,
geolocation, camera access, in-app payments and so on. This plugin-based
architecture lets you include only the features your app needs.

2. The Engine layer contains the core C++ libraries that make up the primitives that
support Flutter apps. The engine implements the low-level primitives of the
Flutter API, such as I/O, graphics, text layout, accessibility, the plugin
architecture and the Dart runtime. The engine is also responsible for rasterizing
Flutter scenes for fast rendering onscreen.

3. The Embedder is different for each target platform and handles packaging the
code as a stand-alone app or embedded module.

raywenderlich.com 35
Flutter Apprentice Chapter 1: Getting Started

Each of the architecture layers is made up of other sublayers and modules, making
them almost fractal. Of particular import to general app development is the makeup
of the framework layer:

The Flutter framework consists of several sublayers:

• At the top is the UI theme, which uses either the Material (Android) or Cupertino
(iOS) design language. This affects how the controls appear, allowing you to make
your app look just like a native one.

• The widget layer is where you’ll spend the bulk of your UI programming time.
This is where you compose design and interactive elements to make up the app.

• Beneath the widgets layer is the rendering layer, which is the abstraction for
building a layout.

• The foundation layer provides basic building blocks, like animations and
gestures, that build up the higher layers.

raywenderlich.com 36
Flutter Apprentice Chapter 1: Getting Started

What’s ahead
This book is divided into five sections:

• Section 1 is the introduction. You’re here! In this section, you’ll get an overview
of Flutter, learn how to get started and make sure you have everything set up to
develop great apps. You’ll build a simple app to get a taste of the Dart language
and Flutter SDKs.

• Section 2 is all about widgets, the building blocks you use to make your app.

• Section 3 covers navigation and deep links. If you think about widgets as making
up screens, navigation ties them together to let the user accomplish various tasks
within the app.

• Section 4 goes over state and data. You’ll learn how to save data and work with
local persistence and networking.

• Section 5 shows you how to make the app work with native platforms as well as
how to deploy your app.

By the end of the book, you’ll be able to take an idea, turn it into a great-looking
multi-platform app and submit it for publication.

Getting started
Now that you’ve decided Flutter is right for you, your next step is to get the tools
necessary to build Flutter apps: the Flutter SDK and Dart compiler. You’ll also need
an IDE with a Flutter plugin along with the tools to build and deploy for the various
platforms. The latter means Xcode for iOS and Android Studio for Android.

To start, visit https://flutter.dev/. This portal is the source of truth for any
installation instructions or API changes that occur between this book’s publication
and the time you read it. If there are any contradictions, the information at
flutter.dev supersedes.

raywenderlich.com 37
Flutter Apprentice Chapter 1: Getting Started

What you need


• A computer. You can develop Flutter apps on Windows, macOS, Linux or
ChromeOS. However, Xcode only runs on macOS, making a Mac necessary to build
and deploy apps for iOS.

Note: Because of the Xcode limitation for macOS, this book uses the Flutter
toolchain on Mac. You can follow along on any platform of your choice — just
skip any iOS- or Mac-specific steps.

• The Flutter SDK.

• An editor, such as Android Studio or Visual Studio code.

• At least one device. You can run in an iOS Simulator or Android emulator, but
running Flutter apps on a physical device will give you the true user experience.

• Developer accounts (optional). To deploy to the Apple App Store or Google Play
Store, you’ll need a valid account on each.

Getting the Flutter SDK


The first step is to download the SDK. You can follow the steps on flutter.dev or
jump right in here: https://flutter.dev/docs/development/tools/sdk/releases

One thing to note is that Flutter organizes its SDK around channels, which are
different development branches. New features or platform support will be available
first on a beta channel for developers to try out. This is a great way to get early
access to certain features like new platforms or native SDK support.

For this book and development in general, use the stable channel. That branch has
been vetted and tested and has little chance of breaking.

Follow the instructions to download the SDK from https://flutter.dev/docs/get-


started/install/macos#get-sdk. Installation is as simple as unarchiving and putting
the bin folder in your path.

raywenderlich.com 38
Flutter Apprentice Chapter 1: Getting Started

Once you do that, you’ll have access to the Flutter command-line app, which is your
starting point. To check you’ve set it up correctly, run the following command in a
terminal:

flutter help

In response, you should see the main help instructions:

Manage your Flutter app development.

Common commands:

flutter create <output directory>


Create a new Flutter project in the specified directory.

flutter run [options]


Run your Flutter application on an attached device or in an
emulator.

Usage: flutter <command> [arguments]


...

These flutter subcommands are a gateway to all the tools that come with Flutter.
You’ll see project management tools, package management tools and tools to run
and test your apps. You’ll dive into many of these in this and future chapters.

Getting everything else


In addition to the Flutter SDKs, you’ll need Java, the Android SDK, the iOS SDKs and
an IDE with Flutter extensions. To make this process easier, Flutter includes the
Flutter Doctor, which guides you through installing all the missing tools.

Just run:

flutter doctor

That checks for all the necessary components and provides the links or instructions
to download ones you’re missing.

Here’s an example:

Doctor summary (to see all details, run flutter doctor -v):
Unable to find any JVMs matching version "1.8".
No Java runtime present, try --request to install.
[✓] Flutter (Channel stable, 2.0.6, on Mac OS X 10.15.7, locale
en-US)
[✗] Android toolchain - develop for Android devices

raywenderlich.com 39
Flutter Apprentice Chapter 1: Getting Started

✗ Flutter requires Android SDK 30 and the Android BuildTools


30.0.2
To update using sdkmanager, run:
"/Users/michael/Library/Android/sdk/tools/bin/
sdkmanager"
"platforms;android-30" "build-tools;30.0.2"
or visit https://flutter.dev/docs/get-started/install/
macos
for detailed instructions.
[!] Xcode - develop for iOS and macOS (Xcode 12.4)
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's
plugin
code that responds to your plugin usage on the Dart
side.
Without CocoaPods, plugins will not work on iOS or
macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[✗] Chrome - develop for the web (Cannot find Chrome executable
at
/Applications/Google Chrome.app/Contents/MacOS/Google
Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a
Chrome executable.
[!] Android Studio (not installed)

[☠] Connected device (the doctor check crashed)


✗ Due to an error, the doctor check did not complete. If the
error message below is not helpful, please let us know
about this issue at https://github.com/flutter/flutter/
issues.
✗ Exception: Unable to run "adb", check your Android SDK
installation and ANDROID_HOME environment variable:
/Users/michael/Library/Android/sdk/platform-tools/adb

! Doctor found issues in 4 categories.

In this example output, Flutter Doctor has identified a series of issues: mainly, no
Java, an outdated Android toolchain and that CocoaPods, Android Studio and Google
Chrome are missing.

The tool has helpfully suggested commands and links to get the missing
dependencies. The tool also terminated before completing, which is common if it
doesn’t find major dependencies.

For your specific setup, follow the suggestions to install whatever you’re missing.
Then keep running flutter doctor until you get all green checkmarks. You’ll likely
have to run it more than a couple of times to clear all the issues.

raywenderlich.com 40
Flutter Apprentice Chapter 1: Getting Started

Note: If Flutter Doctor’s suggestions don’t work, you may have to manually
install missing tools, like Java or Android Studio, by following the instructions
on their respective websites. Just take it one step at a time. Setting up the
development environment is the hardest part of working with Flutter.

Setting up an IDE
The Flutter team officially supports three editors: Android Studio, Visual Studio
Code and Emacs. However, there are many other editors that support the Dart
language, work with the Flutter command line or have third-party Flutter plugins.

This book’s examples use Android Studio, but the code and examples will all work in
your editor of choice. Flutter Doctor will have you install this IDE anyway, to get all
the Android tools, so using Android Studio keeps you from having to install
additional editors. Additionally, Flutter Doctor will tell you to install the Android
Studio Flutter plugin, which also triggers an install of the Dart plugin for Android
Studio.

Once you go through all of the flutter doctor steps, you’ll have everything you
need to create Flutter apps in Android studio. If you see Create New Flutter project
in the Android Studio welcome window, you’re good to go.

raywenderlich.com 41
Flutter Apprentice Chapter 1: Getting Started

Trying it out
Downloading all the components is the hardest part of getting a Flutter app up and
running. Next, you’ll try actually building an app.

There are two recommended ways to create a new project: with the IDE or through
the flutter command-line tool in a terminal. In this chapter, you’ll use the IDE
shortcut and in the next chapter, you’ll use the command line.

In Android Studio, click the Create New Flutter Project option. Leave the default
app selected and click the Next button to continue to the next screen.

For this example, you can keep the default values or change to something more
convenient. Click the Next button to continue.

The options here let you include platform support or change the package name.
You’ll learn more about these options later. For now, click the Finish button.

raywenderlich.com 42
Flutter Apprentice Chapter 1: Getting Started

If you use Visual Studio Code, the process is similar. To create a new project, use
View ▸ Command Palette… ▸ Flutter: New Project. After that, click through the
project form that comes up.

With either editor, you might see pop-ups or messages to download or update
various tools and components. Follow the directions until you resolve the messages.

For example, this Android Studio banner shows: ‘Pub get’ has not been run.
Clicking Get dependencies resolves this.

The template project


The default new project is the same in either editor. It’s a simple Flutter demo. The
demo app counts the number of times you tap a button.

To give it a try, select a connected device, an iOS simulator or an Android emulator.

Launch the app by clicking the Run icon:

raywenderlich.com 43
Flutter Apprentice Chapter 1: Getting Started

It might take a while to compile and launch the first time. When you’re done, you’ll
see the following:

Congratulations, you’ve made your first Flutter app! Click the button and see the
increment response update the label.

raywenderlich.com 44
Flutter Apprentice Chapter 1: Getting Started

All the code for this app is in lib\main.dart in the default project. Feel free to take a
look at it.

Throughout the rest of this book, you’ll dive into Flutter apps, widgets, state, themes
and many other concepts that will help you build beautiful apps.

Bonus: Try hot reload


You’ll learn a lot more about hot reload in future chapters, but it’s just too cool of a
feature to not indulge in a little taste at this point. Before starting, adjust your IDE
window so you can see both it and the simulator or emulator with your app running
in it.

In main.dart, find the following Text widget:

Text(
'You have pushed the button this many times:',
),

Next, change the string to: ‘Thou hast pushed the button this many times:’ to
give it a faux-medieval flair.

Here’s the not-so-tricky part: Just save the file. Now, look at the running app and
observe the change.

Et voila! Your changes reload without stopping the app and redeploying.

raywenderlich.com 45
Flutter Apprentice Chapter 1: Getting Started

Sometimes, saving the file does not automatically trigger the hot reload. In that case,
just press the Hot Reload icon, which looks like a lightning bolt, in the toolbar.

Key points
• Flutter is a software development toolkit from Google for building cross-
platform apps using the Dart programming language.

• With Flutter, you can build a high-quality app that’s performant and looks great,
very quickly.

• Flutter is for both new and experienced developers who wants to start a mobile
app with minimal overhead.

• Install the Flutter SDK and associated tools using instructions found at https://
flutter.dev.

• The flutter doctor command helps you install and update your Flutter tools.

• This book will mostly use Android Studio as the IDE for Flutter development.

raywenderlich.com 46
Flutter Apprentice Chapter 1: Getting Started

Where to go from here?


Your home for all things Flutter is flutter.dev (and dart.dev for the Dart language).
If you get stuck at any of the installation steps, go there for updated instructions.

flutter.dev contains the official documentation and reference pages, which you can
find at https://flutter.dev/docs. These will be your source for complete and up-to-
date information about the SDKs.

Also, there’s https://flutter.dev/community, which has links to all the official Flutter
communities on multiple social media platforms. In particular, check out the Google
Developers’ Flutter YouTube channel: https://www.youtube.com/c/flutterdev/.

Finally, available on raywenderlich.com is The Dart Apprentice, a companion book to


learn more about Dart. For a quick start, check out this free Dart Basics article
https://www.raywenderlich.com/4482551-dart-basics or the video course
Programming in Dart: Fundamentals, available at https://
www.raywenderlich.com/4921688-programming-in-dart-fundamentals.

raywenderlich.com 47
2 Chapter 2: Hello, Flutter
By Michael Katz

Now that you’ve had a short introduction, you’re ready to start your Flutter
apprenticeship. Your first task is to build a basic app from scratch, giving you the
chance to get the hang of the tools and the basic Flutter app structure. You’ll
customize the app and find out how to use a few popular widgets like ListView and
Slider to update its UI in response to changes.

Creating a simple app will let you see just how quick and easy it is to build cross-
platform apps with Flutter — and it will give you a quick win.

By the end of the chapter, you’ll have built a lightweight recipe app. Since you’re just
starting to learn Flutter, your app will offer a hard-coded list of recipes and let you
use a Slider to recalculate quantities based on the number of servings.

raywenderlich.com 48
Flutter Apprentice Chapter 2: Hello, Flutter

Here’s what your finished app will look like:

All you need to start this chapter is to have Flutter set up. If the flutter doctor
results show no errors, you’re ready to get started. Otherwise, go back to Chapter 1,
“Getting Started”, to set up your environment.

Creating a new app


There are two simple ways to start a new Flutter app. In the last chapter, you created
a new app project through the IDE. Alternatively, you can create an app with the
flutter command. You’ll use the second option here.

Open a terminal window, then navigate to the location where you want to create a
new folder for the project. For example, you can use this book’s materials and go to
flta-materials/02-hello-flutter/projects/starter/.

Creating a new project is straightforward. In the terminal, run:

flutter create recipes

This command creates a new app in a new folder, both named recipes. It has the
demo app code, as you saw in the previous chapter, with support for running on iOS
and Android.

raywenderlich.com 49
Flutter Apprentice Chapter 2: Hello, Flutter

Using your IDE, open the recipes folder as an existing project.

Build and run and you’ll see the same demo app as in Chapter 1, “Getting Started”.

Tapping the + button increments the counter.

raywenderlich.com 50
Discovering Diverse Content Through
Random Scribd Documents
"You have suffered from my frantic accusations on that dreadful
July day, but you will never understand the intolerable bitterness of
my punishment, scourged all these dreary, mournful years by keen,
torturing self-reproach. Roy—my own Roy—I am not worthy, but the
world is empty and desolate for me without the one love of my life."
Transcriber Notes:

Throughout the dialogues, there were words used to mimic


accents of the speakers. Those words were retained as-is.

The illustrations have been moved so that they do not break


up paragraphs and so that they are next to the text they
illustrate. Thus the page number of the illustration might not
match the page number in the List of Illustrations, and the
order of illustrations may not be the same in the List of
Illustrations and in the book.

Errors in punctuation and inconsistent hyphenation were not


corrected unless otherwise noted.

On page 60, "possibilty" was replaced with "possibility".


*** END OF THE PROJECT GUTENBERG EBOOK DEVOTA ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like