gpt4 book ai didi

flutter - 如何获取Flutter AlertDialog操作以监视键盘事件(输入键)?

转载 作者:行者123 更新时间:2023-12-03 04:35:17 25 4
gpt4 key购买 nike

有没有一种方法可以使“Enter”键键盘事件突然变为默认值,而不是我的AlertDialog上的操作按钮之一?注意,我指的是在具有物理键盘的网络上使用 flutter 。例如,我有这个对话框:

  Future<void> _confirmDelete(int index) async {
var fp = SessionInfo.of(context).myFloorplans.entries.toList()[index].value;
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Confirm Delete?'),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text("Please confirm deleting ${fp.name}"),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: Text('Delete'),
onPressed: () {
_deleteFloorplan(index);
Navigator.of(context).pop();
},
),
],
);
},
);
}
有没有一种方法可以将键盘上的“enter”键默认为默认值,就像他们按Delete键一样?也许还不是最安全的UI体验,但是大多数情况下只是要求了解此处的基础。
谢谢,
贾斯汀

最佳答案

您唯一需要做的就是将AlertDialog包装在RawKeyboardListener中。
检查这个例子:

RawKeyboardListener(
// its better to initialize and dispose of the focus node only for this alert dialog
focusNode: FocusNode(),
autofocus: true,
onKey: (v) {
if (v.logicalKey == LogicalKeyboardKey.enter) {
_deleteFloorplan(index);
Navigator.pop(context);
}
},
child: your alert dialog ...

关于flutter - 如何获取Flutter AlertDialog操作以监视键盘事件(输入键)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64233092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com