为什么可以通过点击对话框外部来关闭权限对话框,这样做会导致权限被永久拒绝。如何设置可关闭的错误警报对话框。
ovfsdjhp1#
必须在showDialog中将barrierDismissible设置为false
showDialog
barrierDismissible
false
class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( body: Column(children: [ ElevatedButton( onPressed: () { _dialogBuilder(context); }, child: Text('show dialog')) ]), ); } } Future<void> _dialogBuilder(BuildContext context) { return showDialog<void>( barrierDismissible: false, context: context, builder: (BuildContext context) { return AlertDialog( title: const Text('dialog'), content: const Text('accept or reject'), actions: <Widget>[ TextButton( child: const Text('accept'), onPressed: () { Navigator.of(context).pop(); }, ), TextButton( child: const Text('reject'), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }
1条答案
按热度按时间ovfsdjhp1#
必须在
showDialog
中将barrierDismissible
设置为false