如果我们在 BlocProvider 中有 3 个 BLoC,我们可以在同一个 class 中使用 2 个 BLoCBuilder 吗?
If we have 3 BLoCs in the BlocProvider, Can we use 2 BLoCBuilders in the same class?
假设我在 BlocProviderTree 中有 3 个 BLoC,这意味着这些块可用于 class。其中一个用作 BlocListener,现在我希望将其他两个 BLoC 用作 BlocBuilders,因为我需要在同一页面上构建它们的状态。 BlocListener 接受 child 而不是 children。请帮忙!
BlocListener 接受 child 而不是 children。请帮忙!
BlocProviderTree(
blocProviders: [
BlocProvider<EvenBloc>(bloc: _evenBloc),
BlocProvider<SumBloc>(bloc: _sumsBloc,),
BlocProvider<SpacesBloc>(bloc: _spacesBloc,),
],
child: BlocListener(
bloc: _evenBloc,
listener: (BuildContext context, EvenState state) {
if (state is NowEven) {
_sumsBloc.dispatch(LoadSums());
}
},
child: BlocBuilder<SumsEvent,SumsState>(
bloc: _programsBloc,
builder: (BuildContext context, SumsState state) {
if (state is SumsEmpty)
return Container(height: 0.0, width: 0.0,);
if (state is SumsLoading)
return Evens(
child: SpinKitDoubleBounce(
color: darkIndigo,
size: 70.0,
),
);
else if (state is SumsLoaded)
return _body( context,state.sums);
},
)
)
),
如果项目的数量是偶数,我想要带总和的 SpaceNames。我得到的总和是正确的,但 Spaces 在其他集团中。如何定义两个 BlocBuilder?
您可以相互嵌套 BlocBuilder
个:
BlocBuilder(
bloc: BlocProvider.of<Foo>(context),
builder: (context, FooState fooState) {
return BlocBuilder(
bloc: BlocProvider.of<Bar>(context),
builder: (context, BarState barState) {
return Text('$fooState $barState');
},
);
},
);
假设我在 BlocProviderTree 中有 3 个 BLoC,这意味着这些块可用于 class。其中一个用作 BlocListener,现在我希望将其他两个 BLoC 用作 BlocBuilders,因为我需要在同一页面上构建它们的状态。 BlocListener 接受 child 而不是 children。请帮忙!
BlocListener 接受 child 而不是 children。请帮忙!
BlocProviderTree(
blocProviders: [
BlocProvider<EvenBloc>(bloc: _evenBloc),
BlocProvider<SumBloc>(bloc: _sumsBloc,),
BlocProvider<SpacesBloc>(bloc: _spacesBloc,),
],
child: BlocListener(
bloc: _evenBloc,
listener: (BuildContext context, EvenState state) {
if (state is NowEven) {
_sumsBloc.dispatch(LoadSums());
}
},
child: BlocBuilder<SumsEvent,SumsState>(
bloc: _programsBloc,
builder: (BuildContext context, SumsState state) {
if (state is SumsEmpty)
return Container(height: 0.0, width: 0.0,);
if (state is SumsLoading)
return Evens(
child: SpinKitDoubleBounce(
color: darkIndigo,
size: 70.0,
),
);
else if (state is SumsLoaded)
return _body( context,state.sums);
},
)
)
),
如果项目的数量是偶数,我想要带总和的 SpaceNames。我得到的总和是正确的,但 Spaces 在其他集团中。如何定义两个 BlocBuilder?
您可以相互嵌套 BlocBuilder
个:
BlocBuilder(
bloc: BlocProvider.of<Foo>(context),
builder: (context, FooState fooState) {
return BlocBuilder(
bloc: BlocProvider.of<Bar>(context),
builder: (context, BarState barState) {
return Text('$fooState $barState');
},
);
},
);