在Flitter中使用ModalProgressHUD显示微调器,同时ListView.builder从Firebase读取信息
我有一个屏幕,我试图使用Flutter中的Listview.builder以列表的形式读取所有文档。我想使用ModalProgressHUD显示圆形微调器,同时从Firebase读取数据。构建完成后,我希望通过将showSpinner设置为false来停止显示圆形微调器 我可以在窗体屏幕上修改它,但似乎不能在这个视图的所有屏幕上修改它,可能是因为它是一个Listview.builder 提前谢谢 代码如下:在Flitter中使用ModalProgressHUD显示微调器,同时ListView.builder从Firebase读取信息,firebase,flutter,Firebase,Flutter,我有一个屏幕,我试图使用Flutter中的Listview.builder以列表的形式读取所有文档。我想使用ModalProgressHUD显示圆形微调器,同时从Firebase读取数据。构建完成后,我希望通过将showSpinner设置为false来停止显示圆形微调器 我可以在窗体屏幕上修改它,但似乎不能在这个视图的所有屏幕上修改它,可能是因为它是一个Listview.builder 提前谢谢 代码如下: //class wide declaration bool showSpinner =
//class wide declaration
bool showSpinner = true;
Widget build(BuildContext context) {
ExpenseNotifier expenseNotifier = Provider.of<ExpenseNotifier>(context);
Future<void> _resfreshList() async {
expenseNotifier.getExpenses(expenseNotifier);
}
return Scaffold(
body: ModalProgressHUD(
inAsyncCall: showSpinner,
child: RefreshIndicator(
onRefresh: _resfreshList,
child: Consumer<ExpenseNotifier>(
builder: (context, expense, child) {
return expense == null
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
PaddingClass(bodyImage: 'images/empty.png'),
SizedBox(
height: 20.0,
),
Text(
'You don\'t have any expenses',
style: kLabelTextStyle,
),
],
)
: ListView.separated(
itemBuilder: (context, int index) {
var myExpense = expense.expenseList[index];
return Card(
elevation: 8.0,
color: Colors.white70,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
RegularExpenseTextPadding(
regText:
'${_formattedDate(myExpense.updatedAt)}',
),
Container(
margin: EdgeInsets.all(20.0),
padding: const EdgeInsets.all(15.0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(5.0)),
border: Border.all(
color: kThemeStyleBorderHighlightColour),
),
child: Row(
children: <Widget>[
Expanded(
flex: 5,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'${myExpense.amount}',
style: kRegularTextStyle,
),
SizedBox(
height: 20.0,
),
Text(
myExpense.description,
style: kRegularTextStyle,
),
],
),
),
Expanded(
flex: 1,
child: GestureDetector(
onTap: () {
expenseNotifier.currentExpense =
expenseNotifier
.expenseList[index];
Navigator.of(context).push(
MaterialPageRoute(builder:
(BuildContext context) {
return ExpenseDetailsScreen();
}));
},
child: Icon(
FontAwesomeIcons.caretDown,
color: kThemeIconColour,
),
),
),
],
),
),
],
),
);
},
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
height: 20.0,
);
},
itemCount: expenseNotifier.expenseList.length,
);
},
),
),
),
);
}
//类范围声明
bool showSpinner=true;
小部件构建(构建上下文){
ExpenseNotifier ExpenseNotifier=Provider.of(上下文);
Future\u resfreshList()异步{
expenseNotifier.GetExpense(expenseNotifier);
}
返回脚手架(
正文:ModalProgressHUD(
inAsyncCall:showSpinner,
子:刷新指示器(
onRefresh:\u resfreshList,
儿童:消费者(
构建者:(上下文、费用、子项){
退货费用==null
?立柱(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
PaddingClass(bodyImage:'images/empty.png'),
大小盒子(
身高:20.0,
),
正文(
“你没有任何费用”,
风格:kLabelTextStyle,
),
],
)
:ListView.separated(
itemBuilder:(上下文,int索引){
var myExpense=费用.支出列表[索引];
回程卡(
标高:8.0,
颜色:颜色。白色70,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
经常性支出(
regText:
“${u formattedDate(myExpense.updatedAt)}”,
),
容器(
裕度:所有边缘集(20.0),
填充:常数边集全部(15.0),
装饰:盒子装饰(
边界半径:
边界半径所有(半径圆形(5.0)),
边界:边界(
颜色:KThemestyleBorderHighlightColor),
),
孩子:排(
儿童:[
扩大(
弹性:5,
子:列(
横轴对齐:
CrossAxisAlignment.start,
儿童:[
正文(
“${myExpense.amount}”,
风格:kRegularTextStyle,
),
大小盒子(
身高:20.0,
),
正文(
myExpense.description,
风格:kRegularTextStyle,
),
],
),
),
扩大(
弹性:1,
儿童:手势检测器(
onTap:(){
expenseNotifier.currentExpense=
费用通知人
.expenseList[索引];
导航器.of(上下文).push(
MaterialPage路线(建筑商:
(构建上下文){
返回ExpenseDetailsScreen();
}));
},
子:图标(
FontAwesomeIcons.caretDown,
颜色:KTHEMECICONCOLUR,
),
),
),
],
),
),
],
),
);
},
separatorBuilder:(BuildContext,int索引){
返回大小框(
身高:20.0,
);
},
itemCount:expenseNotifier.expenseList.length,