If we want to display different pages, we will have to implement logic inside of our list to determine when to display specific pages. We can accomplish these updates by creating a Stream and nesting our Navigator in a StreamBuilder.
Create a new file called auth_service.dart and add the following:
import 'dart:async';
// 1
enum AuthFlowStatus { login, signUp, verification, session }
// 2
class AuthState {
final AuthFlowStatus authFlowStatus;
AuthState({this.authFlowStatus});
}
// 3
class AuthService {
// 4
final authStateController = StreamController<AuthState>();
// 5
void showSignUp() {
final state = AuthState(authFlowStatus: AuthFlowStatus.signUp);
authStateController.add(state);
}
// 6
void showLogin() {
final state = AuthState(authFlowStatus: AuthFlowStatus.login);
authStateController.add(state);
}
}
Open main.dart again and add create an instance of AuthService in _MyAppState.
... // class _MyAppState extends State<MyApp> { (line 15)
final _authService = AuthService();
... // @override
AuthService needs to be imported to main.dart
... // import 'sign_up_page.dart'; (line 3)
import 'auth_service.dart';