6. Describes the
configuration for an
Element.
An instantiation of a
Widget at a particular
location in the tree.
Handles size, layout,
and painting.
Flutter has three trees.
Element - Lifecycle RenderObject - PaintWidget - Configure
- https://www.youtube.com/watch?v=996ZgFRENMs
7. Lifecycle - Stateless Widget
Don’t rebuild, and it is immutable, you can’t change the state of the widget.
1. createElement
2. build
8. Lifecycle - Stateful Widget
Rebuild, It is mutable, and the state of the Widget can be changed and
it will be notified when a state changed.
1. createState
● When creating StatefulWidget, it will be called.
2. initState
● Only be called once.
3. didChangeDependencies
● After initState, it will be called.
● When the InheritedWidget changes, it will be called.
4. build
9. Lifecycle - Stateful Widget
5. didUpdateWidget
● After build, it will be called.
● After hot reload, it will be called.
● If the parent widget calls setState(), the child widget's didUpdateWidget will be called.
6. setState
● Call setState, build and redraw.
7. build
8. deactivate
● It will only be called when the State Widget is temporarily removed,
such as the page is changed.
9. dispose
● The State Widget will only be called when it is destroyed forever.
Interact with Widget
Remove widget or leave page
10. What seems to be the problem?
- https://flutter.dev/docs/development/data-and-backend/state-mgmt/options
26. “Dio is a powerful Http client, which supports
Interceptors, Global configuration, FormData,
Request Cancellation, File downloading, Timeout.
- https://pub.dev/packages/dio
27. Dio
Init
Dio dio = Dio(new BaseOptions(
baseUrl: ‘https://api.xyzabc.com/’,
connectTimeout: 5000,
receiveTimeout: 100000,
contentType: ContentType.json.toString(),
responseType: ResponseType.json,
));
28. Dio
GET
Future<BikeListItem> fetchBikes() async {
final response = await _dio.get("youbike");
return BikeListItem.fromJson(response.data);
}
POST
Future<LoginItem> login(LoginRequest request) async {
final response = await _dio.post(
"v1/basicLogin",
data: request,
);
return LoginItem.fromJson(response.data["data"]);
}