Created
April 27, 2019 18:07
-
-
Save felangel/4371b2ce1f9b9e30b36dbea7d15633f6 to your computer and use it in GitHub Desktop.
[flutter_firbase_login] App (5)
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/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 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