Exemplo n.º 1
0
        protected override Widget createWidget()
        {
            //Redux配置store
            var store = new Store <AppState>(
                //reduce中判断action类型返回state
                reducer: AppReducer.Reduce,
                //initialState: new AppState());
                //使用本地存储
                initialState: AppState.Load(),
                ReduxPersistMiddleware.create <AppState>());

            //Redux通过provider使用store
            return(new StoreProvider <AppState>(
                       store: store,
                       child: new StoreConnector <AppState, MaterialColor>(
                           (context, model, dispatcher) =>
                           new MaterialApp(
                               theme: new ThemeData(
                                   //传入model值
                                   primarySwatch: model),
                               home: new HomePage()),
                           //转换操作
                           converter: state => state.themeColor.ToMaterialColor()


                           )
                       ));
        }
Exemplo n.º 2
0
        protected override Widget createWidget()
        {
            var store = new Store <ExampleState>((state, action) =>
            {
                switch (action)
                {
                case IncreaseCountAction _:
                    return(new ExampleState
                    {
                        Count = state.Count + 1
                    });

                case DecreaseCountAction _:
                    return(new ExampleState
                    {
                        Count = state.Count - 1
                    });
                }

                return(state);
            },
                                                 // 3.call load
                                                 ExampleState.Load(),
                                                 // 4.add middleware
                                                 ReduxPersistMiddleware.create <ExampleState>());

            return(new StoreProvider <ExampleState>(store,
                                                    child: new StoreConnector <ExampleState, int>(
                                                        converter: state => state.Count,
                                                        builder: (context, model, dispatcher) =>
            {
                return new Row(
                    children: new List <Widget>()
                {
                    new FlatButton(
                        child: new Text("-"),
                        onPressed: () => { dispatcher.dispatch(new DecreaseCountAction()); }
                        ),
                    new Text(model.ToString()),
                    new FlatButton(
                        child: new Text("+"),
                        onPressed: () => { dispatcher.dispatch(new IncreaseCountAction()); }
                        )
                }
                    );
            }
                                                        )
                                                    ));
        }
Exemplo n.º 3
0
        protected override Widget createWidget()
        {
            var store = new Store <AppState>(AppReducer.Reduce, AppState.Load(),
                                             ReduxPersistMiddleware.create <AppState>());

            return(new StoreProvider <AppState>(
                       store: store,
                       child: new MaterialApp(
                           localizationsDelegates: new List <LocalizationsDelegate <MaterialLocalizations> >()
            {
                CustomLocalizationDelegate.Del,
                DefaultMaterialLocalizations.del
            },
                           supportedLocales: CustomLocalizationDelegate.SupportedLocales,
                           theme: new ThemeData(
                               primarySwatch: Colors.deepPurple,
                               accentColor: Colors.black,
                               iconTheme: new IconThemeData(
                                   color: Colors.black
                                   ),
                               textTheme: new TextTheme(
                                   headline: new TextStyle(
                                       fontFamily: "Sans Bold",
                                       fontWeight: FontWeight.bold,
                                       fontSize: 24,
                                       color: Colors.black
                                       ),
                                   title: new TextStyle(
                                       fontFamily: "Sans Bold",
                                       fontWeight: FontWeight.bold,
                                       fontSize: 20,
                                       color: Colors.black
                                       ),
                                   subhead: new TextStyle(
                                       fontFamily: "Sans Regular",
                                       fontWeight: FontWeight.normal,
                                       fontSize: 18,
                                       color: Colors.black
                                       ),
                                   body1: new TextStyle(
                                       fontFamily: "Sans Regular",
                                       fontWeight: FontWeight.normal,
                                       fontSize: 16,
                                       color: Colors.black
                                       ),
                                   body2: new TextStyle(
                                       fontFamily: "Sans Regular",
                                       fontWeight: FontWeight.normal,
                                       fontSize: 16,
                                       color: Colors.black
                                       ),
                                   subtitle: new TextStyle(
                                       fontFamily: "Sans Regular",
                                       fontWeight: FontWeight.normal,
                                       fontSize: 14,
                                       color: Colors.black
                                       )
                                   )
                               ),
                           home: new NoteList()
                           )
                       ));
        }