Last active
February 10, 2020 04:04
-
-
Save kitoko552/b21184d0cbb88456ed47c79d94015448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final store = Store<AppState>( | |
reducer, | |
initialState: AppState.init(), | |
); | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: StoreProvider( | |
store: store, | |
child: MyHomePage( | |
increment: () { | |
store.dispatch(UpdateCount(store.state.count + 1)); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({ | |
Key key, | |
@required this.increment, | |
}) : super(key: key); | |
final VoidCallback increment; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Demo'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('You have pushed the button this many times:'), | |
StoreConnector<AppState, int>( | |
distinct: true, | |
converter: (store) => store.state.count, | |
builder: (context, count) { | |
return Text( | |
'$count', | |
style: Theme.of(context).textTheme.display1, | |
); | |
}, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: increment, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment