关于flutter-redux的部分知识点,未整理

参考文档:
http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_basic_usages.html
http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_two_async_operations.html
https://segmentfault.com/a/1190000015579633

flutter-redux,主要用于项目的状态管理

通过store保存保存所有的数据
state是某个时点的数据,通过store.subscript监听state的变化
state的数据与被渲染到view层
view 层通过store.dispatch()发出通知action给store修改状态state
发出action,重新计算state的过程被成为reducer,这个过程中可以设置中间件

class MyApp extends StatelessWidget {

  final Store store;

  MyApp({this.store});

  @override
  Widget build(BuildContext context) {
    return new StoreProvider(store: store, child: new MaterialApp(
        home:  new StoreConnector(builder: (BuildContext context,int counter){
        return new MyHomePage(title: 'Flutter Demo Home Page',counter:counter);
      }, converter: (Store store){
        return store.state;
      }) ,
    ));
  }
}

使用flutter-redux,最外层要被StoreProvider控件包裹,否则会报错

new StoreConnector(builder: (BuildContext context,int counter){
        return new MyHomePage(title: 'Flutter Demo Home Page',counter:counter);
      }, converter: (Store store){
        return store.state;
      }) 

使用StoreConnector控件将state传递到view,一定需要使用converter将Store中的状态转变成组件需要的状态,这里的builder函数的第二个参数就是converter函数的返回值

你可能感兴趣的:(关于flutter-redux的部分知识点,未整理)