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 saveEmotion({String emotionDescription}) { | |
| //... | |
| store.dispatch( | |
| SaveEmotion( |
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 SavedEmotionsListItem extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return InkWell( | |
| onTap: () { | |
| //... | |
| store.dispatch(ViewEmotion(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 NavigateToCreateEmotion { | |
| final String emoji; | |
| final String emotion; | |
| const NavigateToCreateEmotion({this.emoji, this.emotion}); | |
| } | |
| class SaveEmotion { | |
| final String emotion; | |
| final String emotionDescription; |
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
| List<Middleware<EmotionAppState>> createLoginMiddleware( | |
| [DataProvider provider]) { | |
| final navigateToCreateNewEmotion = _navigateToCreateNewEmotion(provider); | |
| return [ | |
| TypedMiddleware<EmotionAppState, NavigateToCreateEmotion>( | |
| navigateToCreateNewEmotion), | |
| ]; | |
| } | |
| Middleware<EmotionAppState> _navigateToCreateNewEmotion(DataProvider provider) { |
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, NavigateToCreateEmotion>( | |
| _handleNavigateToCreateNewEmotion) | |
| ]); | |
| EmotionAppState _handleNavigateToCreateNewEmotion( | |
| EmotionAppState previousState, NavigateToCreateEmotion action) { | |
| EmotionAppState state; | |
| state = previousState.copy( | |
| newState: EmotionAppState(emoji: action.emoji, emotion: action.emotion)); |
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
| List<Middleware<EmotionAppState>> createLoginMiddleware( | |
| [DataProvider provider]) { | |
| final saveEmotion = _saveEmotion(provider); | |
| return [ | |
| TypedMiddleware<EmotionAppState, SaveEmotion>(saveEmotion), | |
| ]; | |
| } | |
| Middleware<EmotionAppState> _saveEmotion(DataProvider provider) { | |
| return (Store<EmotionAppState> store, action, NextDispatcher next) async { |
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
| List<Middleware<EmotionAppState>> createLoginMiddleware( | |
| [DataProvider provider]) { | |
| final viewEmotion = _viewEmotions(provider); | |
| return [ | |
| TypedMiddleware<EmotionAppState, ViewEmotion>(viewEmotion) | |
| ]; | |
| } | |
| Middleware<EmotionAppState> _viewEmotions(DataProvider provider) { |
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, ViewEmotion>(_handleViewEmotion), | |
| ]); | |
| EmotionAppState _handleViewEmotion( | |
| EmotionAppState previousState, ViewEmotion action) { | |
| EmotionAppState state; | |
| state = previousState.copy(newState: EmotionAppState(index: action.index)); | |
| 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 | |
| void didChangeDependencies() { | |
| //... | |
| store.dispatch(LoadEmotions()); | |
| //... | |
| } | |
| } |
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
| List<Middleware<EmotionAppState>> createLoginMiddleware( | |
| [DataProvider provider]) { | |
| final loadEmotions = _loadEmotions(provider); | |
| return [ | |
| TypedMiddleware<EmotionAppState, LoadEmotions>(loadEmotions) | |
| ]; | |
| } | |
| Middleware<EmotionAppState> _loadEmotions(DataProvider provider) { |