我对 flutter blocs 非常陌生,并且在 bloc 实现方面遇到了一些问题,我正在尝试在启动屏幕小部件中的状态更改后进行导航。
状态更新到InitSuccess后,它应该导航到LoginScreen,但此导航会发生很多次。
我无法理解状态更改为InitSuccess后要做什么,此后块保持活动状态并调用许多次LoginScreen。
启动画面
class SplashScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
SplashBloc _splashBloc;
final _scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
_init();
super.initState();
}
@override
void dispose() {
_splashBloc.dispose();
super.dispose();
}
void _init() {
Future.delayed(Duration.zero, () {
checkDeviceConnection(context);
BlocSupervisor().delegate = SplashBlocDelegate();
final bool isIOS = Theme.of(context).platform == TargetPlatform.iOS;
_splashBloc = SplashBloc(
firebaseService: FirebaseService(context),
authService: AuthService(context),
devicesService: DevicesService(context),
); …Run Code Online (Sandbox Code Playgroud)