【发布时间】:2023-04-04 16:56:01
【问题描述】:
我正在开发一个使用多个对话框用于多种目的的颤振应用程序。 在我们的代码中,在某些情况下用户可以打开一个对话框。在此对话框中,有一些按钮也会打开另一个对话框。结果是 2 个对话框相互叠加,背景屏幕非常暗。 我们想做的是一次只显示一个对话框。我们怎样才能做到这一点?
这里有一个简单的代码来说明我们的问题:
class MyScreen extends StatelessWidget {
@override
build(BuildContext context) {
return FlatButton(
child: Text('Button'),
onPressed: () async {
final resultDialog = await showDialog<ResultDialog1>(
context: context,
builder: (BuildContext context) => MyFirstDialog(),
);
// Do some stuff with the result, so this part of the tree cannot be destroyed
},
);
}
}
class MyFirstDialog extends StatelessWidget {
@override
build(BuildContext context) {
return FlatButton(
child: Text('Button in first dialog'),
onPressed: () async {
final resultDialog = await showDialog<ResultDialog2>(
context: context,
builder: (BuildContext context) => MySecondDialog(), // <- This will appear on top of the first dialog
);
// Do some stuff with the result, so this part of the tree cannot be destroyed
},
);
}
}
class MySecondDialog extends StatelessWidget {
@override
build(BuildContext context) {
return Text('Second Dialog');
}
}
【问题讨论】:
标签: flutter dart dialog flutter-web