Created
March 11, 2021 10:36
-
-
Save lempiy/06e019fd76ae2beb0ec89edaa4acea7a to your computer and use it in GitHub Desktop.
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
class AppInSessionState extends StatelessWidget { | |
final Widget child; | |
const AppInSessionState({Key key, this.child}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final sessionBloc = Provider.of<SessionBloc>(context); | |
return BlocProvider<AuthorBloc>( | |
builder: (_, bloc) => bloc ?? AuthorBloc(sessionBloc, AuthorApi()), | |
onDispose: (_, bloc) => bloc.dispose(), | |
child: BlocProvider<BottomBarBloc>( | |
builder: (_, bloc) => bloc ?? BottomBarBloc(), | |
onDispose: (_, bloc) => bloc.dispose(), | |
child: BlocProvider<QuestBloc>( | |
builder: (_, bloc) => bloc ?? QuestBloc(sessionBloc, QuestApi()), | |
onDispose: (_, bloc) => bloc.dispose(), | |
child: child, | |
), | |
), | |
); | |
} | |
} | |
class AppState extends StatelessWidget { | |
final Widget child; | |
const AppState({Key key, this.child}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return BlocProvider<SessionBloc>( | |
builder: (_, sessionBloc) => | |
sessionBloc ?? | |
SessionBloc( | |
authApi: AuthApi(), targetPlatform: Theme.of(context).platform), | |
onDispose: (_, bloc) => bloc.dispose(), | |
child: AppInSessionState(child: child), | |
); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AppState( | |
child: MaterialApp(), | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment