Worldwide Praise for Flutter App Development: How to Write for iOS and Android at Once....5
Table of Contents....7
About the Author....16
About the Technical Reviewer....17
Who Is This Book For?....18
Foreword....23
Preface....25
Chapter 1: Hello Flutter....27
What Is Flutter?....28
Why Flutter?....29
The Other Options....30
Native Solutions....31
Conclusion....32
Chapter 2: Developing in Flutter....33
The Flutter Toolchain....34
The Flutter SDK....34
Installing the Flutter SDK....34
IDEs....34
VS Code from Microsoft....35
Android Studio/IntelliJ from JetBrains....35
Which IDE Should I Use?....35
IDE DevTools....36
Emulators....37
iOS Simulator....37
Android Emulator....38
Keeping the Tools Up to Date....39
Flutter doctor....40
Flutter Upgrade....41
The Flutter Development Process....42
Scaffolding the App and Files....43
Anatomy of a Flutter Project....43
Running Your App....45
Running It As a Web App....46
Running It on a Tethered Device....47
Hot Reloading....47
Debugging....48
Conclusion....49
Chapter 3: Everything Is Widgets....50
UI As Code....53
Built-In Flutter Widgets....54
Value Widgets....55
Layout Widgets....56
Navigation Widgets....56
Other Widgets....57
How to Create Your Own Stateless Widgets....57
Widgets Have Keys....61
Passing a Value into Your Widget....62
Stateless and Stateful Widgets....64
So Which One Should I Create?....64
Conclusion....65
Chapter 4: Value Widgets....66
The Text Widget....66
The Icon Widget....67
The Image Widget....69
Embedded Images....70
Network Images....71
Sizing an Image....71
SnackBar Widget....74
Input Widgets....76
Text Fields....77
Making Your TextField Fancy....77
Password Boxes....78
Adjusting the Soft Keyboard....79
Restricting the Data That Can Be Typed....80
Checkboxes....81
Radio Buttons....82
Sliders....84
Dropdowns....85
Putting the Form Widgets Together....87
Form Widget....87
FormField Widget....89
TextFormField and DropdownButtonFormField....90
onSaved....91
validator....91
Submitting the Form....92
One Big Form Example....93
Conclusion....93
Chapter 5: Responding to Gestures....94
Meet the Button Family....95
ElevatedButton....97
TextButton and IconButton....97
FloatingActionButton (FAB)....97
SegmentedButton....98
CupertinoButton....99
Dismissible....99
Custom Gestures for Your Custom Widgets....100
Step 1: Decide on Your Gestures and Behaviors....101
Step 2: Create Your Custom Widget....101
Step 3: Add a GestureDetector widget....102
Step 4: Associate Your Gesture with Its Behavior....103
Example 1: Reacting to a Long Press....103
Example 2: Pinching to Add a New Item....105
Example 3: Swiping Left or Right....106
Conclusion....108
Chapter 6: Navigation and Routing....109
Stack Navigation....110
Navigating Forward and Back....111
Using Anonymous Routes....112
Get Result After a Scene Is Closed....113
Drawer Navigation....114
The Drawer Widget....115
Filling the Drawer....117
Tab Navigation....119
DefaultTabController....120
TabBarView....121
TabBar and Tabs....121
TabBar at the Bottom....122
The Dialog Widget....123
showDialog() and AlertDialog....124
Responses with a Dialog....125
Navigation Methods Can Be Combined....126
Chapter 7: Managing State....128
What Is State?....128
The Shape of a StatefulWidget....130
The Most Important Rule About State!....131
Passing State Down....132
Lifting State Back Up....133
An Example of State Management....135
When Should We Use State?....139
Conclusion....141
Chapter 8: State Management Libraries....142
The InheritedWidget....142
The BLoC Pattern....143
Some Libraries....144
ScopedModel....144
Redux and Hooks....145
Provider....145
Whoa! That’s a Lot of Packages!....145
Raw State....146
Riverpod....147
1. Install flutter_riverpod....148
2. Wrap Your App with a ProviderScope....148
3. Write a Provider....149
Wait, What Is This Provider You Speak Of?....149
4. Inherit from ConsumerStateWidget....149
5. Read Data with ref.watch()....150
6. Write Data with ref.read()....151
Conclusion....151
Chapter 9: Making RESTful API Calls with HTTP....152
What Is an API Call?....153
The Flavors of API Requests....154
Making an HTTP GET or DELETE Request....155
Making an HTTP PUT, POST, or PATCH Request....157
HTTP Responses to Widgets....158
Brute Force – The Easy Way....158
FutureBuilder – The Clean Way....159
StreamBuilder....161
Strongly Typed Classes....163
Create a Business Class....163
Write a .fromJSON() Method....164
Use .fromJSON() to Hydrate the Object....164
One Big Example....165
Overview of the App....166
Create the Flutter App....168
Making a Strongly Typed Business Class....169
list_people.dart....170
A GET Request in Flutter....173
A DELETE Request in Flutter....173
upsert_person.dart....174
A POST and PUT Request in Flutter....175
Conclusion....176
Chapter 10: Styling with Themes....177
Thinking in Flutter Styles....177
Individual Styles....178
Styling Text....178
Mass-Changing Values....180
Themes....181
1. ColorScheme....182
2. TextTheme....186
3. Widget-Specific Themes....188
4. Put Them Together in a Theme....189
5. Override the Styles on Individual Widgets....190
Final Styling Thoughts....191
A Word About Colors....191
Custom Fonts....193
Conclusion....196
Chapter 11: Laying Out Your Widgets....198
Our Approach....198
1. Layout the Entire Screen (a.k.a. Scene)....199
2. Position Widgets Above and Below Each Other or Side by Side....199
3. Handle Situations When We Run Out of Space and Overflow the Scene....201
4. Handle Extra Space in the Scene....201
5. Make Finer Adjustments in Positioning....202
Laying Out the Whole Scene....202
MaterialApp Widget....203
The Scaffold Widget....204
The AppBar Widget....206
SafeArea Widget....207
Flutter’s Layout Algorithm....208
The Dreaded “Unbounded Height” Error....208
The Algorithm Itself....212
Conclusion....215
Chapter 12: Layout – Positioning Widgets....216
Putting Widgets Next to or Below Others....216
Responsive Design....218
Responsive Design in Flutter....218
Flex and MediaQuery....219
Conclusion....220
Chapter 13: Layout – Fixing Overflows....221
Overflow Warning Bars....221
Our Options to Correct Overflows....222
A Sample Problem to Solve....223
1. Allow the Children to Wrap....225
2. Squeeze the Children Until They Fit....226
3. Allow the User to Scroll....228
SingleChildScrollView Widget....229
The ListView Widget....231
ListView Is Memory Efficient....231
ListView Is Very Flexible....232
Regular ListView....233
ListView.builder: When You’re Building Widgets from a List of Objects....233
GridView Widget....234
GridView.extent()....235
GridView.count()....236
Conclusion....238
Chapter 14: Layout – Filling Extra Space....239
What if There’s Extra Space Left Over?....240
mainAxisAlignment....240
crossAxisAlignment....242
IntrinsicWidth....243
Expanded Widget....244
Open Space with Expandeds....247
Conclusion....248
Chapter 15: Layout – Fine-Tuning Positioning....249
Container Widget and the Box Model....250
EdgeInsets for Padding and Margin....251
Alignment and Positioning Within a Container....252
Container Sizes Are Not Obvious....254
Container Decorations....256
Border....259
BorderRadius....260
BoxShape....262
Conclusion....264
Chapter 16: Layout – Special Presentation Widgets....265
Slivers....265
Stack Widget....266
Positioned Widget....268
Card Widget....270
The Table Widget....271
Conclusion....274
Appendix A: Dart Language Overview....275
What Is Dart?....275
Expected Features – Dart Cheat Sheet....276
Data Types....276
Arrays/Lists....277
Conditional Expressions....277
Looping....278
Classes....278
Class Constructors....279
Unexpected Things About Dart....279
Type Inference....279
final vs. const....280
Null Safety....281
String interpolationwith $....282
Multiline Strings....282
Spread Operator....283
Map....283
Functions Are Objects....283
Big Arrow/Fat Arrow/Lambda....284
Named Function Parameters....284
Omitting “new” and “this.”....285
Class Constructor Parameter Shorthand....286
Private Class Members....287
Mixins....287
The Cascade Operator (..)....288
No Overloading....289
Named Constructors....289
Appendix B: Futures, Async, and Await....291
Flutter Apps Use an Event Loop....291
Why Would It Wait?....292
How Do We Get the Data from a Future?....293
Await....294
Async....295
Summary....296
Appendix C: Including Packages in Your Flutter App....297
Finding a Library to Use....297
Downloading the Library....299
The pubspec.yaml File....300
Using These Packages in Your Code....301
Keeping Your Packages Current....302
How to Upload Your Own Library....303
Appendix D: How to Work with Files....306
Including a File with Your App....307
Writing a File....308
And Reading It!....309
Using JSON....310
Writing Your App’s Memory to JSON....311
Reading JSON into Your App’s Memory....312
Shared Preferences....313
To Write Preferences....314
To Read Preferences....314
Conclusion....315
Appendix E: How to Debug Your Layout....316
Index....320
Create apps for iOS and Android phones and tablets using Flutter, a Google framework that produces two outputs for a single app. Let’s face it, creating iOS apps using Apple tools such as Swift and Xcode is extremely complicated. Creating Android apps with Kotlin and Android Studio is just as difficult. This book breaks down complex concepts and tasks into easily digestible segments with examples, full-color pictures, and hands-on labs with starters and solutions.As you work through the accompanying lab exercises, you’ll learn the Dart programming language; the entire Flutter development toolchain; the differences between stateful and stateless widgets; and a working knowledge of the architecture of apps. You’ll work with themes and styles, develop custom widgets, and even teach your app to respond to gestures like taps, swipes, and pinches. You’ll also design, create, and control the layout of your app. Create tools to handle form data entry from users. And ultimately create killer multiscreen apps with navigation, menus, and tabs.You’ll see that with Flutter, you can write an app one time that produces two outputs: one that can be submitted to the Apple App Store and another that can be uploaded to the Google Play Store. In short, one code creates the same app that runs on iPhones, iPads, Android phones and tablets, virtually all devices. And if you like, it can also create a version that runs on Macs, Windows, Linux, and in browsers!Flutter App Development explains difficult topics in plain, everyday terms that simplify the process of writing mobile apps.
Developers who have coded in JavaScript, Python, Java, C#, C++, or any similar language. Managers, product owners, and business analysts who need to understand Flutter’s capabilities.