我正在使用 flutter_bloc 库来管理应用程序的状态,因为我在 bloc 类中按下了不同类状态更改中的按钮,但无法在构建方法中侦听 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,
),
),
),
],
),
);