【发布时间】:2019-05-24 03:22:46
【问题描述】:
有一块屏幕有MyBloc myBloc
在screen的build方法中是这样的:
Widget build(BuildContext context) {
return MyCustomLoadingStack( //My custom widget to have the main content below the loading widget
_buildContent(context), //My main content
_buildLoading(context)); //My loading on top
}
还有我的2个方法:
Widget _buildContent(BuildContext context) {
return Column(children: <Widget>[
OtherWidgetOne(),
OtherWidgetTwo(),
BlocBuilder<MyEvent, MyState>(
bloc: myBloc,
builder: (BuildContext context, MyStatestate) {
switch (state.type) {
case MyStateList.doneWorking:
return MyDataWidget(); // this content cares about displaying the data only
default:
return Container(); //otherwise display nothing
}
},
)
]);
}
Widget _buildLoading(BuildContext context) {
return BlocBuilder<MyEvent, MyState>(
bloc: myBloc,
builder: (BuildContext context, MyState state) {
switch (state.type) {
case MyStateList.loading:
return LoadingView(); //This _buildLoading cares the loading only
default:
return Container(); //If it's not loading the show nothing for the loading layer
}
},
)
}
我的问题是内容当前显示数据的时间。当我yield MyState(type: MyStateList.loading) 在做其他事情时显示加载(比如为当前显示的数据加载更多)。两个BlocBuilder 都被调用,然后_buildContent(context) 什么也不显示,因为它不满足MyStateList.doneWorking 条件。当然,_buildLoading(context) 会在下面显示一个空内容的加载。
无论如何我可以跳过 _buildContent(context) 中的 BlocBuilder 以继续显示当前数据并仍然在顶部加载吗?
我想有一个小部件来包含数据或空Container() 以在_buildContent(context) 的默认情况下使用,但这对我来说没有意义,因为它们可能会重新呈现相同的小部件。
感谢您的宝贵时间。
【问题讨论】: