Created
April 27, 2019 18:06
-
-
Save felangel/f29e8ac5798fc74765fb46ea47b44d03 to your computer and use it in GitHub Desktop.
[flutter_firebase_login] App (4)
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/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(); | |
} | |
return Container(); | |
}, | |
), | |
), | |
); | |
} | |
@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