This file contains hidden or 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
| final emotionAppReducer = combineReducers<EmotionAppState>([ | |
| TypedReducer<EmotionAppState, LoadedEmotions>(_handleLoadedEmotions) | |
| ]); | |
| EmotionAppState _handleLoadedEmotions( | |
| EmotionAppState previousState, LoadedEmotions action) { | |
| EmotionAppState state; | |
| state = previousState.copy( | |
| newState: EmotionAppState(details: action.details, loadComplete: true)); | |
| return state; |
This file contains hidden or 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 _MyHomePageState extends State<MyHomePage> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return StoreConnector<EmotionAppState, _ViewModel>( | |
| converter: _ViewModel.fromStore, | |
| builder: (context, vm) { | |
| if (vm.isLoading()) { | |
| widgets.add( | |
| Align( | |
| alignment: Alignment.center, |
This file contains hidden or 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 _ViewModel { | |
| final Store<EmotionAppState> store; | |
| const _ViewModel({this.store}); | |
| static _ViewModel fromStore(Store<EmotionAppState> store) { | |
| return _ViewModel(store: store); | |
| } | |
| bool isLoading() => !store.state.loadComplete; | |
| } |
This file contains hidden or 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 SavedEmotionsList extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return StoreConnector<EmotionAppState, _ViewModelSavedEmotion>( | |
| converter: _ViewModelSavedEmotion.fromStore, | |
| builder: (context, vm) { | |
| return ListView.builder( | |
| itemBuilder: (BuildContext context, int index) => | |
| SavedEmotionsListItem( | |
| index: index, |
This file contains hidden or 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 _ViewModelSavedEmotion { | |
| final Store<EmotionAppState> store; | |
| const _ViewModelSavedEmotion({this.store}); | |
| static _ViewModelSavedEmotion fromStore(Store<EmotionAppState> store) { | |
| return _ViewModelSavedEmotion(store: store); | |
| } | |
| String getEmotionImage(int index) { | |
| return store.state.details[index].emoji; | |
| } |
This file contains hidden or 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 _AddDetailState extends State<AddDetail> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return StoreConnector<EmotionAppState, _ViewModel>( | |
| converter: _ViewModel.fromStore, | |
| builder: /*...*/ | |
| child: Center( | |
| child: Text( | |
| vm.getEmotionType(), | |
| style: TextStyle(fontSize: 72.0), |
This file contains hidden or 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 _ViewModel { | |
| final Store<EmotionAppState> store; | |
| const _ViewModel({this.store}); | |
| static _ViewModel fromStore(Store<EmotionAppState> store) { | |
| return _ViewModel(store: store); | |
| } | |
| String getEmotionType() { | |
| return store.state.emoji; | |
| } |
This file contains hidden or 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 _ViewDetailState extends State<ViewDetail> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return StoreConnector<EmotionAppState, _ViewModel>( | |
| converter: _ViewModel.fromStore, | |
| builder: (context, vm) { | |
| /*...*/ | |
| child: Center( | |
| child: Text( | |
| vm.getEmotionImage(), |
This file contains hidden or 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 _ViewModel { | |
| final Store<EmotionAppState> store; | |
| const _ViewModel({this.store}); | |
| static _ViewModel fromStore(Store<EmotionAppState> store) { | |
| return _ViewModel(store: store); | |
| } | |
| String getEmotionImage() { | |
| int index = store.state.index; | |
| return store.state.details[index].emoji; |
This file contains hidden or 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 _ViewModel { | |
| final Store<EmotionAppState> store; | |
| const _ViewModel({this.store}); | |
| static _ViewModel fromStore(Store<EmotionAppState> store) { | |
| return _ViewModel(store: store); | |
| } | |
| void addEmotionDescription(String emotionType, String emotionDescription) { | |
| store.dispatch(NavigateToAction.push('/add-emotion', preNavigation: () { | |
| //... | |
| })); |