// One simple action: Incrementenum Actions {
Increment
}// The reducer, which takes the previous count and increments it in response// to an Increment action.intcounterReducer(int state,dynamic action){if(action == Actions.Increment){return state +1;}return state;}voidmain(){// Create your store as a final variable in a base Widget. This works better// with Hot Reload than creating it directly in the `build` function.final store =newStore<int>(counterReducer,initialState:0);runApp(newFlutterReduxApp(
title:'Flutter Redux App',
store: store,));}classFlutterReduxAppextendsStatelessWidget{final String title;final Store<int> store;FlutterReduxApp({Key key,this.store,this.title}):super(key:key);@override
Widget build(BuildContext context){// The StoreProvider should wrap your MaterialApp or WidgetsApp. This will// ensure all routes have access to the store.return StoreProvider<int>(
store: store,
child:newMaterialApp(
theme:newThemeData.dark(),
title: title,
home:ScaffoldDemo(title,store),),);}}classScaffoldDemoextendsStatelessWidget{final String title;final Store<int> store;ScaffoldDemo(this.title,this.store);@override
Widget build(BuildContext context){returnScaffold(
appBar:AppBar(title:Text(title),),
body:Center(
child:Column(
children:<Widget>[Text('you have click the button many times:'),
StoreConnector<int,String>(
converter:(store)=>store.state.toString(),
builder:(context,count){returnText(
count,
style: Theme.of(context).textTheme.display1,);},)],),),
floatingActionButton:newStoreConnector<int, VoidCallback>(
converter:(store){// Return a `VoidCallback`, which is a fancy name for a function// with no parameters. It only dispatches an Increment action.return()=> store.dispatch(Actions.Increment);},
builder:(context, callback){returnnewFloatingActionButton(// Attach the `callback` to the `onPressed` attribute
onPressed: callback,
tooltip:'Increment',
child:newIcon(Icons.add),);},),);}}