Created
April 27, 2019 18:27
-
-
Save felangel/4f1677d24dcd6a485213341b232fbb96 to your computer and use it in GitHub Desktop.
[flutter_firebase_login] App (6)
This file contains 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
import 'package:flutter/material.dart'; | |
import 'package:bloc/bloc.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:flutter_firebase_login/authentication_bloc/bloc.dart'; | |
import 'package:flutter_firebase_login/user_repository.dart'; | |
import 'package:flutter_firebase_login/home_screen.dart'; | |
import 'package:flutter_firebase_login/login/login.dart'; | |
import 'package:flutter_firebase_login/splash_screen.dart'; | |
import 'package:flutter_firebase_login/simple_bloc_delegate.dart'; | |
main() { | |
BlocSupervisor().delegate = SimpleBlocDelegate(); | |
runApp(App()); | |
} | |
class App extends StatefulWidget { | |
State<App> createState() => _AppState(); | |
} | |
class _AppState extends State<App> { | |
final UserRepository _userRepository = UserRepository(); | |
AuthenticationBloc _authenticationBloc; | |
@override | |
void initState() { | |
super.initState(); | |
_authenticationBloc = AuthenticationBloc(userRepository: _userRepository); | |
_authenticationBloc.dispatch(AppStarted()); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return BlocProvider( | |
bloc: _authenticationBloc, | |
child: MaterialApp( | |
home: BlocBuilder( | |
bloc: _authenticationBloc, | |
builder: (BuildContext context, AuthenticationState state) { | |
if (state is Uninitialized) { | |
return SplashScreen(); | |
} | |
if (state is Unauthenticated) { | |
return LoginScreen(userRepository: _userRepository); | |
} | |
if (state is Authenticated) { | |
return HomeScreen(name: state.displayName); | |
} | |
}, | |
), | |
), | |
); | |
} | |
@override | |
void dispose() { | |
_authenticationBloc.dispose(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment