[英]Use custom dialogs in Flutter FutureBuilder waiting
I have a request to the server, when I use FutureBuilder, the ConnectionState.waiting section, I want to use a custom dialog, but after ConnectionState.done, this dialog does not close, it does not even do Navigator.pop(context).我对服务器有一个请求,当我使用 FutureBuilder 时,ConnectionState.waiting 部分,我想使用自定义对话框,但是在 ConnectionState.done 之后,这个对话框没有关闭,它甚至不执行 Navigator.pop(context) . enter image description here enter image description here
在此处输入图片描述 在此处输入图片描述
Try this试试这个
Before ConnectionState.waiting
just call this onLoading(context);
在
ConnectionState.waiting
之前调用这个onLoading(context);
then然后
if(ConnectionState. done){
Navigator.pop();
}
void onLoading(BuildContext context) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Center(child: CircularProgressIndicator(color: Colors.blue));
});
}
Unfortunately, it is not possible to disable Alert Dialog using object orientation, and I designed dialogs on a separate page, and Navigator.pop() does not work, but with this method, I achieved my desired result.不幸的是,无法使用 object 方向禁用警报对话框,并且我在单独的页面上设计了对话框,并且 Navigator.pop() 不起作用,但是通过这种方法,我达到了我想要的结果。
FutureBuilder(
future: _futureEditName,
builder: (context,snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
ShowWaitingDialog(context,true);
}else if(snapshot.connectionState == ConnectionState.done && snapshot.hasData){
ShowWaitingDialog(context,false)
}
}
);
show and dismiss Alert Dialog显示和关闭警报对话框
ShowWaitingDialog(BuildContext context,bool show) {
showDialog(
context: context,
builder: (context) {
return show == true ?
AlertDialog(
insetPadding: const EdgeInsets.all(20),
alignment: Alignment.center,
title: Container(
width: double.maxFinite,
child: Column(
textDirection: TextDirection.rtl,
children: [
Row(
textDirection: TextDirection.rtl,
children: [
const SpinKitCircle(
color: Colors.lightBlue,
size: 35,
),
const SizedBox(width: 20,),
Container(
alignment: Alignment.center,
child: const Text(
'please wait',
style: TextStyle(
color: kGraydark,
fontSize: 15,
),
),
),
],
),
],
),
),
)
: FutureBuilder(builder: (context, snapshot) {
Navigator.of(context).pop();
Navigator.of(context).pop();
return Container();
},);
},);
} }
Navigator.of(context).pop() It must be called twice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.