在所有教程和示例中,在runApp()中仅启动一个单个MaterialApp。进行下面的操作是否有任何副作用?在下面的代码中,AppWrapper返回包装了MaterialApp的四个StatelessWidget中的一个。
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();
},
);
}
}