Существуют ли какие-либо побочные эффекты обмена MaterialApp в зависимости от состояния аутентификации? - PullRequest
0 голосов
/ 29 февраля 2020

Во всех руководствах и примерах в runApp () инициируется только один единственный MaterialApp. Есть ли побочные эффекты от того, что я делаю ниже? В приведенном ниже коде AppWrapper возвращает один из четырех StatelessWidget, который оборачивает MaterialApp.

void main() async {
  ...
  runApp(
    BlocProvider(
      create: (context) => AuthenticationBloc(
        authenticationRepository: authenticationRepository,
      )..add(AppStarted()),
      child: AppWrapper(),
    ),
  );
}

class AppWrapper extends StatelessWidget {
  const AppWrapper({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<AuthenticationBloc, AuthenticationState>(
      builder: (context, state) {
        if (state is AuthenticationInitial) {
          return SplashScreen();
        }
        if (state is AuthenticationNotAuthenticated) {
          return NotAuthenticatedApp();
        }
        if (state is AuthenticationIsAuthenticated) {
          return IsAuthenticatedApp();
        }
        return FourOFourScreen();
      },
    );
  }
}
...