2019.05.05
Flutter 状态管理
Flutter的很多灵感来自于React,它的设计思想是数据与视图分离,由数据映射渲染视图。所以在Flutter中,它的Widget是immutable的,而它的动态部分全部放到了状态(State)中。
Scoped Model
Redux
BLoC
BLoC
2019.05.06
Widget - State - BuildContext - InheritedWidget
- Widgets: related to layout;
- Widgets Tree: widgets are organized in tree structures;
- BuildContext: a reference to the location of a widget with in the widgets tree. a BuildContext only belongs to one widget.
- Stateless Widget: 创建之后就无法再改变的控件,比如Text,Row,Container,不会rebuild;
- Stateful Widget: 创建之后可以根据状态发生变化;widget.color;
- State: 状态的改变会影响控件的行为和布局,触发rebuild;State会和BuildContext绑定,绑定之后称为mounted,只有mounted之后,才可以setState;State mounted之后,不能直接被其他BuildContext访问;
- Stateful Widget Life Circle: constructor() -> createState() -> constructor() -> initState(){ controllers, animations, … } -> mounted -> didChangeDependencies(){ listeners } -> build() { build widgets } -> dispose() { controllers, listeners, …} ;
- 在 widget 的生命周期中,是否需要根据变量的变化来 rebuild widget;
- Widget unique identity - key:widgets的唯一标识,可以通过key来获取widget;
- State -> BuildContext -> Widget Instance:通过key来访问 state;
- InheritedWidget:实现在widget tree中高效O(1)共享信息;
Reactive Programming - Streams - BLoC
- BlocBase
- BlocProvider
- ApplicationBloc
- LoginBloc
- RxDart
dependencies:
bloc:^0.8.0
flutter_bloc:^0.5.0
equatable:^0.1.6
2019.05.07
2019.05.13
构造方法:
构造方法不会被子类继承;
convenient constructors;
named constructors;
initializer list;
initializer list -> superclass’s no-arg constructor -> main class’s no-arg constructor;
redirecting constructors;
factory constructors;
2019.05.14
使用SingleChildScrollView避免超出边界。
本地图片路径名称。
shared_preference 引入问题,增加pod xcconfig,编码问题。