main.dart (2193B)
1 import 'package:bloc/bloc.dart'; 2 import 'package:flutter/cupertino.dart'; 3 import 'package:flutter/material.dart'; 4 import 'package:flutter_bloc/flutter_bloc.dart'; 5 6 import 'blocs/AuthenticationBloc.dart'; 7 import 'components/LoadingIndicator.dart'; 8 import 'events/AuthenticationEvent.dart'; 9 import 'repos/UserRepository.dart'; 10 import 'states/AuthenticationState.dart'; 11 import 'views/HomePage.dart'; 12 import 'views/SplashPage.dart'; 13 14 class SimpleBlocDelegate extends BlocDelegate { 15 @override 16 void onEvent(Bloc bloc, Object event) { 17 super.onEvent(bloc, event); 18 //print(event); 19 } 20 21 @override 22 void onTransition(Bloc bloc, Transition transition) { 23 super.onTransition(bloc, transition); 24 //print(transition); 25 } 26 27 @override 28 void onError(Bloc bloc, Object error, StackTrace stacktrace) { 29 super.onError(bloc, error, stacktrace); 30 //print(error); 31 } 32 } 33 34 void main() { 35 BlocSupervisor.delegate = SimpleBlocDelegate(); 36 final userRepository = UserRepository(); 37 38 runApp( 39 BlocProvider<AuthenticationBloc>( 40 create: (context) { 41 return AuthenticationBloc(userRepository: userRepository) 42 ..add(AppStarted()); 43 }, 44 child: App( 45 userRepository: userRepository, 46 ), 47 ), 48 ); 49 } 50 51 class App extends StatelessWidget { 52 final UserRepository userRepository; 53 54 App({ 55 Key key, 56 @required this.userRepository, 57 }) : super(key: key); 58 59 @override 60 Widget build(BuildContext context) { 61 return MaterialApp( 62 title: 'Bahnhofsfotos', 63 theme: ThemeData( 64 primaryColor: Color(0xffc71c4d), 65 accentColor: Color(0xffD0C332), 66 ), 67 home: BlocBuilder<AuthenticationBloc, AuthenticationState>( 68 builder: (context, state) { 69 if (state is AuthenticationUninitialized) { 70 return SplashPage(); 71 } 72 if (state is AuthenticationAuthenticated) { 73 return HomePage(); 74 } 75 if (state is AuthenticationNeeded) { 76 return HomePage(); 77 } 78 if (state is AuthenticationLoading) { 79 return LoadingIndicator(); 80 } else { 81 return HomePage(); 82 } 83 }, 84 ), 85 ); 86 } 87 }