我使用flutter_bloc库来管理应用的状态,因为我在群类中按了不同类状态更改的按钮,但无法在生成方法中侦听 BlocProvider。
BlocBuilder<AppBarBloc, bool>( builder: (context, isEnabled) { print('state detected'); return Container(); },)
//in main.dart were providing the Blocs
MultiBlocProvider( providers: [ BlocProvider ( builder: (BuildContext context) => PagesBloc(), ), BlocProvider ( builder: (BuildContext context) => AppBarBloc(), ), ], child: Column( children: [ Expanded( child: MaterialApp( title: 'Flutter Demo', initialRoute: '/', onGenerateRoute: RouteGenerator.generateRoute, theme: ThemeData( primarySwatch: Colors.blue, ), ), ), ], ), );
也许你可以检查这个链接关于集团听众。https://bloclibrary.dev/#/recipesfluttershowsnackbar 但是,作为您可以执行的一个示例: BlocBuilder<CustomerRegisterBloc, CustomerRegisterState> buildCustomerRegisterOnState() { return BlocBuilder<CustomerRegisterBloc, CustomerRegisterState>( builder: (context, state) { if (state is InitialCustomerRegisterState) { return PersonalDataForm(); } if (state is PasswordCustomerRegisterState) {} if (state is PaymentFormCustomerRegisterState) {} if (state is TermsCustomerRegisterState) {} return Container(); }, ); }
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。