小编Der*_*ens的帖子

颤振集团模式向后导航导致错误状态

我对带有抖动的集团平台有疑问/问题。目前,我正在这样启动我的应用

class _MyAppState extends State<MyApp> {

@override
  Widget build(BuildContext context) {        
    return BlocProvider(
        bloc: MyBloc(),
        child: MaterialApp(
          title: "MyApp",
          home: MyHomePage(),    
          routes: {
            '/homePage': (context) => MyHomePage(),
            '/otherPage': (context) => OtherPage(),
            '/otherPage2': (context) => OtherPage2(),
            ...
          },
        ));
Run Code Online (Sandbox Code Playgroud)

这样我就可以像这样检索/访问myBloc

myBloc = BlocProvider.of(context) as MyBloc;
Run Code Online (Sandbox Code Playgroud)

和状态所代表的数据

BlocBuilder<MyBlocEvent, MyObject>(
    bloc: myBloc,
    builder: (BuildContext context, MyObject myObject) {         
     ....
     var t = myObject.data;
     ....
     myBloc.onFirstEvent();
     ...
 }; 
Run Code Online (Sandbox Code Playgroud)

无论我在哪里需要它。

MyBloc是这样实现的:

abstract clas MyBlocEvent {}
class FirstEvent extends MyBlocEvent {}
class SecondEvent extends MyBlocEvent {} …
Run Code Online (Sandbox Code Playgroud)

navigation stream flutter

7
推荐指数
2
解决办法
1463
查看次数

标签 统计

flutter ×1

navigation ×1

stream ×1