所以我跟踪了bloc login tutorial个,虽然我设法完成了它,但我仍然是Ffltter&;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();
}
},
),
),
);
我已try 添加Navigation.Push包装退货,如下所示:
if (state is AuthenticationUninitialized) {
Navigation.push(
return SplashPage();
),
}
但是,虽然在语法上没有错误,但这会使应用程序崩溃.有没有人知道在维护BLOC示例的同时实现这一点的方法?谢谢.