Last active
November 16, 2019 04:09
-
-
Save juliuscanute/cba53856de3bea6c4506d0ced4793993 to your computer and use it in GitHub Desktop.
[Store Provider] #dart #store #provider #appstate #redux
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 AuthCheckAuthenticatedAction{ | |
@override | |
String toString() { | |
return 'AuthCheckAuthenticatedAction{name: AuthCheckAuthenticatedAction}'; | |
} | |
} |
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<LoginAppState>> createLoginMiddleware( | |
[QRRepository repository]) { | |
final performAuthenticationCheck = _performAuthenticationCheck(repository); | |
return [ | |
TypedMiddleware<LoginAppState, AuthCheckAuthenticatedAction>( | |
performAuthenticationCheck), | |
NavigationMiddleware<LoginAppState>() | |
]; | |
} | |
Middleware<LoginAppState> _performAuthenticationCheck(QRRepository repository) { | |
return (Store<LoginAppState> store, action, NextDispatcher next) async { | |
AuthCheckAuthenticatedAction requestAction = action; | |
next(action); | |
}; | |
} |
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 loginAppReducer = combineReducers<LoginAppState>([ | |
TypedReducer<LoginAppState, MoveToScreen>(_moveToScreenState), | |
]); | |
LoginAppState _moveToScreenState(LoginAppState appState, MoveToScreen action) { | |
return LoginAppState(screen: action.screen); | |
} |
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
@immutable | |
class LoginAppState { | |
final Screen screen; | |
LoginAppState({this.screen}); | |
} |
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 Store<LoginAppState> store = new Store<LoginAppState>( | |
loginAppReducer, | |
initialState: LoginAppState(screen: Screen.Login), | |
middleware: createLoginMiddleware(...), | |
); | |
@override | |
Widget build(BuildContext context) { | |
return StoreProvider<LoginAppState>( | |
store: store, | |
child: MaterialApp(...), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment