无法听取来自Bloc Flutter的新价值

时间:2019-12-03 15:15:33

标签: android ios flutter bloc flutter-bloc

我正在使用flutter_bloc库来管理应用程序的状态,因为在不同类状态下按下按钮时,bloc类发生了变化,但无法在build方法中侦听BlocProvider。

BlocBuilder<AppBarBloc, bool>(
          builder: (context, isEnabled) {
            print('state detected');
            return Container();
          },)

//in main.dart were providing the Blocs


MultiBlocProvider(
      providers: [
        BlocProvider<PagesBloc>(
          builder: (BuildContext context) => PagesBloc(),
        ),
        BlocProvider<AppBarBloc>(
          builder: (BuildContext context) => AppBarBloc(),
        ),
      ],
      child: Column(
        children: <Widget>[
          Expanded(
            child: MaterialApp(
              title: 'Flutter Demo',
              initialRoute: '/',
              onGenerateRoute: RouteGenerator.generateRoute,
              theme: ThemeData(
                primarySwatch: Colors.blue,
              ),
            ),
          ),
        ],
      ),
    );

1 个答案:

答案 0 :(得分:1)

也许您可以检查有关bloc listener的链接。

但是,作为您可以做什么的一个示例:

List<String> templateArguments = new ArrayList<(Arrays.asList(args));
templateArguments.add(throwable.getMessage());
String.format(template, templateArguments.toArray());