如何在此等待功能删除数据时添加加载屏幕?
How to add Loading screen while this await function delete data?
I want to add a loading screen when the screen pops and while it deletes the data from the firestore.
onPressed: () async {
Navigator.pop(context);
await Firestore.instance
.collection('projects')
.document(id)
.delete();
storage.ref().child(imagename).delete();
})
创建class
class LoaderDialog {
static Future<void> showLoadingDialog(BuildContext context, GlobalKey key) async {
var wid = MediaQuery.of(context).size.width / 2;
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.only(left: 130 , right: 130),
child: Dialog(
key: key,
backgroundColor: Colors.white,
child: Container(
width: 60.0,
height: 60.0,
child: Image.asset(
'images/loaderOld.gif',
height: 60,
width: 60,
),
)
),
);
},
);
}
}
如何调用:在你的Class(你想显示加载程序的地方)。
final GlobalKey _LoaderDialog = new GlobalKey();
显示
LoaderDialog.showLoadingDialog(context, _LoaderDialog);
隐藏
Navigator.of(_LoaderDialog.currentContext,rootNavigator: true).pop();
您可以添加任何 UI
I want to add a loading screen when the screen pops and while it deletes the data from the firestore.
onPressed: () async {
Navigator.pop(context);
await Firestore.instance
.collection('projects')
.document(id)
.delete();
storage.ref().child(imagename).delete();
})
创建class
class LoaderDialog {
static Future<void> showLoadingDialog(BuildContext context, GlobalKey key) async {
var wid = MediaQuery.of(context).size.width / 2;
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.only(left: 130 , right: 130),
child: Dialog(
key: key,
backgroundColor: Colors.white,
child: Container(
width: 60.0,
height: 60.0,
child: Image.asset(
'images/loaderOld.gif',
height: 60,
width: 60,
),
)
),
);
},
);
}
}
如何调用:在你的Class(你想显示加载程序的地方)。
final GlobalKey _LoaderDialog = new GlobalKey();
显示
LoaderDialog.showLoadingDialog(context, _LoaderDialog);
隐藏
Navigator.of(_LoaderDialog.currentContext,rootNavigator: true).pop();
您可以添加任何 UI