Last active
February 10, 2020 04:00
-
-
Save kitoko552/d7c7fa87fb0fb008d5fb798b34c05b9b 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 Handler { | |
Handler({ | |
this.increment, | |
}); | |
final VoidCallback increment; | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: StoreProvider( | |
store: Store<AppState>( | |
reducer, | |
initialState: AppState.init(), | |
), | |
child: Provider( | |
create: (context) { | |
return Handler( | |
increment: () { | |
final store = StoreProvider.of<AppState>(context); | |
store.dispatch(UpdateCount(store.state.count + 1)); | |
}, | |
); | |
}, | |
child: const MyHomePage(), | |
), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final handler = Provider.of<Handler>(context, listen: false); | |
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: handler.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