【发布时间】:2021-07-08 18:53:49
【问题描述】:
final _sectionFormKey = GlobalKey<FormState>();
...
TextButton.icon(
onPressed: _addSection,
icon: Icon(Icons.info_outline_rounded),
label: Text("open"),
),
...
_addSection() {
return showDialog<void>(
context: context,
builder: (context) => PlatformAlertDialog(
title: Text(translate("other_details.extra_sections")),
content: Form(
key: _sectionFormKey,
child: Text(translate("other_details.extra_sections_info")),
),
actions: <Widget>[
TextButton(
child: new PlatformText((translate('ok'))),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
}
如果我在按钮上单击太快(一个显示对话框,然后再次单击背景关闭它)我会收到以下错误:
'package:flutter/src/widgets/will_pop_scope.dart':断言失败: 第 135 行 pos 12: '_route == ModalRoute.of(context)': is not true.
'package:flutter/src/widgets/framework.dart':断言失败:行 4954 pos 14: '_dependents.isEmpty': 不正确。
要么断言表明框架本身存在错误,要么我们 应在此错误消息中提供更多信息 帮助您确定并解决根本原因。
【问题讨论】:
-
如果你使用
Navigator.pop(context);会发生什么?