Part1 Meet Flutter: The Widget Tree Widget Types and The State Object 60
Part1 Meet Flutter: The Widget Tree Widget Types and The State Object 60
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
1/3
4.4 Common layout and UI widgets 112
■ Table widget 116 ■ TabBar widget 122
4.5 ListView and builders 126
5 User interaction: Forms and gestures 129
5.1 User interaction and gestures 130
The GestureDetector widget 130 ■ GestureDetector in
practice 131 ■ The Dismissible widget 134
5.2 Flutter forms 136
The Form widget 137 ■ GlobalKey<FormState> 138 ■ The structure
of the AddCityPage form 138 ■ Implementing the form in the weather
app 140
5.3 FormField widgets 141
The TextFormField widget 142 ■ The DropdownFormButton
widget 143 ■ Generic form fields 146
5.4 Form UI and working with focus nodes 147
InputDecoration 147 ■ Improving the UI with FocusNodes 149
5.5 Managing form state with form methods 151
Form.onChange 152 ■ FormState.save 153
Form.onWillPop 155
5.6 Summary 157
6 Pushing pixels: Flutter animations and using the canvas 158
6.1 Introducing Flutter animations 159
Tweens 160 ■ Animation curves 161 ■ Ticker providers 162
AnimationController 162 ■ AnimatedWidget 163 ■ Implement
ing the animation controller and tween for the background 166
6.2 CustomPainter and the canvas 172
The shapes used to make up the clouds 173 ■ Defining the
CustomPainter and the Paint object 173 ■ The CustomPainter
paint method 175
6.3 Staggered animations, TweenSequence, and built-in animations 179
Creating a custom animation state class 179 ■ Built-in animation
widgets: SlideTransition 182 ■ Building animations for the
Clouds widget 184 ■ TweenSequence 185
6.4 Reusable custom color transition widgets 187
PART 3 STATE MANAGEMENT AND ASYNCHRONOUS DART .................189
7 Flutter routing in depth 191
7.1 Routing in Flutter 192
The Farmers Market app 192 ■ The app source code 193
7.2 Declarative routing and named routes 193
Declaring routes 194 ■ Navigating to named routes 195
MaterialDrawer widget and the full menu 197 ■ Menu items
and the appropriate widgets: ListView and ListItems 198
NavigatorObserver: Highlighting the active route with
RouteAware 201
7.3 Routing on the fly 204
MaterialRouteBuilder 204 ■ showSnackBar, showBottomSheet,
and the like 205
7.4 Routing animations 209
7.5 Summary 211
8 Flutter state management 212
8.1 Deep dive into StatefulWidgets 213
The widget tree and the element tree 213 ■ The StatefulWidget
lifecycle and when to do what 214
8.2 Pure Flutter state management: The InheritedWidget 216
Creating a Central Store wth an InheritedWidget/StatefulWidget
team 218 ■ The inheritFromWidgetOfExactType and of
methods 218 ■ Use the of method to lift up state 222
2/3
State management patterns beyond Flutter 224
8.3 Blocs: Business Logic Components 225
How do blocs work? 227 ■ Implementing the bloc
architecture 228 ■ Intro to streams and async Dart 231
Implementing streams in the CartBloc 232
8.4 Summary 235
9 Async Dart and Flutter and infinite scrolling 236
9.1 Async Dart 237
Future recap 237 ■ The async/await keywords 239 ■ Catching
errors with futures 240 ■ Catching errors with try and catch 241
9.2 Sinks and streams (and StreamControllers) 242
Anatomy of the observer pattern with Dart streams 243
Implementing streams 243 ■ Broadcasting streams 245
Higher-order streams 247
9.3 Using streams in blocs 250
Blocs use inputs and outputs 250 ■ Implementing a bloc input 253
9.4 Async Flutter: StreamBuilder 254
9.5 Infinite and custom scrollable widgets 255
CustomScrollView and slivers 256 ■ Catalog widget scroll view 256
The SliverGrid widget 260 ■ Delegates 260 ■ Custom slivers 261
PART 4 BEYOND FOUNDATIONS ........................................265
10 Working with data: HTTP, Firestore, and JSON 267
10.1 HTTP and Flutter 268
HTTP package 269 ■ GET requests 269
10.2 JSON serialization 270
Manual serialization 271 ■ Auto-generated JSON serialization 275
Updating the Todo class 275 ■ Bringing it all together in the UI 277
10.3 Working with Firebase in Flutter 281
Installing Firestore 282 ■ Create a Firestore project 283
Configure your app 283 ■ Add Firebase to your pubspec 286
Using Firestore 286
10.4 Dependency injection 288
10.5 Summary 291
11 Testing Flutter apps 292
11.1 Tests in Flutter 293
Dart unit tests 293 ■ Using mockito to test methods that need external
dependencies 297 ■ Flutter widget tests 300 ■ Flutter integration
tests 303 ■ Performance profiling integration tests 307
11.2 Accessibility with the semantics widgets 310
11.3 Next steps with Flutter 311
3/3