所以我一直在关注bloc login tutorial,虽然我设法完成了它,但我对 Flutter & Dart 还是很陌生。
有一部分代码根据状态返回不同的小部件,而不是新的 Scaffold。由于它不使用路由,因此页面之间的过渡看起来不连贯且尴尬。
return BlocProvider<AuthenticationBloc>(
bloc: authenticationBloc,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: BlocBuilder<AuthenticationEvent, AuthenticationState>(
bloc: authenticationBloc,
builder: (BuildContext context, AuthenticationState state) {
if (state is AuthenticationUninitialized) {
return SplashPage();
}
if (state is AuthenticationAuthenticated) {
return HomePage();
}
if (state is AuthenticationUnauthenticated) {
return LoginPage(userRepository: userRepository);
}
if (state is AuthenticationLoading) {
return LoadingIndicator();
}
},
),
),
);
我尝试添加一个 Navigation.push 包装返回,如下所示:
if (state is AuthenticationUninitialized) {
Navigation.push(
return SplashPage();
),
}
但是,虽然在语法上没有错误,但这会使应用程序崩溃。有谁知道在维护 BLoC 示例的同时实现这一点的方法?谢谢。