我正在使用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,
),
),
),
],
),
);
答案 0 :(得分:1)
也许您可以检查有关bloc listener的链接。
但是,作为您可以做什么的一个示例:
List<String> templateArguments = new ArrayList<(Arrays.asList(args));
templateArguments.add(throwable.getMessage());
String.format(template, templateArguments.toArray());