Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Last active November 16, 2019 04:09
Show Gist options
  • Save juliuscanute/cba53856de3bea6c4506d0ced4793993 to your computer and use it in GitHub Desktop.
Save juliuscanute/cba53856de3bea6c4506d0ced4793993 to your computer and use it in GitHub Desktop.
[Store Provider] #dart #store #provider #appstate #redux
class AuthCheckAuthenticatedAction{
@override
String toString() {
return 'AuthCheckAuthenticatedAction{name: AuthCheckAuthenticatedAction}';
}
}
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);
};
}
final loginAppReducer = combineReducers<LoginAppState>([
TypedReducer<LoginAppState, MoveToScreen>(_moveToScreenState),
]);
LoginAppState _moveToScreenState(LoginAppState appState, MoveToScreen action) {
return LoginAppState(screen: action.screen);
}
@immutable
class LoginAppState {
final Screen screen;
LoginAppState({this.screen});
}
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