【发布时间】:2019-08-30 01:21:09
【问题描述】:
所以我关注了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 示例的同时实现这一点的方法?谢谢。
【问题讨论】:
标签: flutter flutter-animation bloc