在 Flutter 中,我希望使用键盘事件,问题是当我按下向下键时,在 keyDown 和 keyUp 事件上都会发生操作,在代码示例中,代码将在按键时和释放按键时打印单词两次,我希望它只在 keyDown 事件上打印它并忽略 keyUp,以便在按下键并释放它后在控制台中打印一次
谢谢
import 'package:flutter/services.dart'; //<-- needed for the keypress comparisons
FocusNode focusNode = FocusNode(); // <-- still no idea what this is.
@override
Widget build(BuildContext context) {
FocusScope.of(context).requestFocus(focusNode); // <-- yup. magic. no idea.
return Scaffold(
appBar: AppBar(),
body: RawKeyboardListener(
autofocus: true,
focusNode: focusNode, // <-- more magic
onKey: (RawKeyEvent event) {
if (event.data.logicalKey == LogicalKeyboardKey.arrowDown) {
print(down);
}
},
child: GridView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: 300,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 30),
itemBuilder: …
Run Code Online (Sandbox Code Playgroud) void main() {
List<Map<String, dynamic>> products = [
{'id': 24, 'time': '2019-11-24 00:00:00.000'},
{'id': 36, 'time': '2019-11-23 00:00:00.000'},
{'id': 48, 'time': '2019-11-24 00:00:00.000'},
];
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我想将“id”48的“时间”条目“2019-11-24 00:00:00.000”替换为“2019-10-26 00:00:00.000”。