Asm*_*oun 1 dart flutter flutter-layout
我有一个带有图标的小部件,当我单击它时,会显示一个对话框小部件,这是对对话框的调用:
// this icon is in widget parent
IconButton(
icon: Icon(
Icons.info_outline,
size: mobileWidth * 0.07,
),
tooltip: 'information',
color: Colors.blueGrey,
onPressed: () {
showAlertInfo(context, code);
setState(() {});
},
),
Run Code Online (Sandbox Code Playgroud)
这是我的对话框:
showAlertInfo(BuildContext context, String code) {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return AlertDialog(
title: Text(
"Information sur le client $code", ),
content: SingleChildScrollView(
child: Container( .....
/* ...
this dialog has some operations that changes info
values of the widget that called this in first place
it is a big code to put here*/
// here I have a close button
actions: [
FlatButton(
child: Text(
"Fermer",
style: TextStyle(
color: Colors.red,
fontSize: mobileWidth * 0.035,
fontWeight: FontWeight.bold,
),
),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
),
],
);
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当对话框关闭时,我希望更新父小部件,那么setState当对话框小部件关闭时,如何调用父小部件?
添加await之前showDialog()并setState((){})在下一行调用。
await showDialog(
context: context,
builder: (context) {
return yourWidget;
}
);
setState((){});
Run Code Online (Sandbox Code Playgroud)
使用.then()回调并调用setState((){})它。
await showDialog(
context: context,
builder: (context) {
return yourWidget;
}
);
setState((){});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1748 次 |
| 最近记录: |