仅当在一个函数中调用 2 showDialog() 时才显示 Flutter 显示对话框
Flutter show dialog show only if 2 showDialog() is called in one function
我在flutter web中有一个showDialog()函数,但它只能这样工作(2个在一个函数中显示对话框),如果我注释掉另一个,对话框将不会显示。我真的不明白为什么我需要放置 2 showDialog() 才能显示它。这是代码:
onDeleteTap(String id) async {
print(id);
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Hapus?'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
],
),
),
actions: <Widget>[
TextButton(
child: Text('Batal'),
onPressed: () {
},
),
SizedBox(
width: 150.0,
child: ErrorButton(
text: "Hapus",
onClick: () {
},
),
),
],
);
},
);
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Hapus?'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
],
),
),
actions: <Widget>[
TextButton(
child: Text('Batal'),
onPressed: () {
},
),
SizedBox(
width: 150.0,
child: ErrorButton(
text: "Hapus",
onClick: () {
},
),
),
],
);
},
);
我认为在调用 onDeleteTap 之前,您必须使用 navigator.pop(context)。您可以通过不显示任何对话框来检查您是否真的弹出屏幕(如果弹出屏幕,您当前的屏幕将关闭或者您将看到黑屏),或者您可以使用调试器检查所有通过的行在获取此代码之前。
我在flutter web中有一个showDialog()函数,但它只能这样工作(2个在一个函数中显示对话框),如果我注释掉另一个,对话框将不会显示。我真的不明白为什么我需要放置 2 showDialog() 才能显示它。这是代码:
onDeleteTap(String id) async {
print(id);
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Hapus?'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
],
),
),
actions: <Widget>[
TextButton(
child: Text('Batal'),
onPressed: () {
},
),
SizedBox(
width: 150.0,
child: ErrorButton(
text: "Hapus",
onClick: () {
},
),
),
],
);
},
);
await showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Hapus?'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
],
),
),
actions: <Widget>[
TextButton(
child: Text('Batal'),
onPressed: () {
},
),
SizedBox(
width: 150.0,
child: ErrorButton(
text: "Hapus",
onClick: () {
},
),
),
],
);
},
);
我认为在调用 onDeleteTap 之前,您必须使用 navigator.pop(context)。您可以通过不显示任何对话框来检查您是否真的弹出屏幕(如果弹出屏幕,您当前的屏幕将关闭或者您将看到黑屏),或者您可以使用调试器检查所有通过的行在获取此代码之前。