如何解决Flutter:FocusScope 在发布模式下不工作
我正在创建一个 Flutter 桌面应用程序,并且在 Release 模式下 FocusScope
没有检测到键盘事件。在调试模式下一切正常。知道我怎样才能让它正常工作吗?
也许我可以给我的客户调试文件夹,因为它工作正常,而不是发布。除了大小之外还有其他显着差异吗?由于两个版本的加载速度都很快,我似乎无法识别出任何值得注意的东西。
我的代码如下:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int counter = 0;
late FocusNode _focusNode;
@override
dispose() {
_focusNode.dispose();
}
@override
void initState() {
_focusNode = FocusNode();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method,and use it to set our appbar title.
title: Text("Test App"),),body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
children: <Widget>[
Text(
counter.toString(),FocusScope(
child: TextField(),onKey: (_focusNode,event) {
if (event.toString().contains('RawKeyDownEvent') && event.toString().contains('Arrow Up')) {
print(event.toString());
setState(() {
counter--;
}
);
return KeyEventResult.handled;
}
if (event.toString().contains('RawKeyDownEvent') && event.toString().contains('Arrow Down')) {
print(event.toString());
setState(() {
counter++;
}
);
return KeyEventResult.handled;
}
if (event.toString().contains('RawKeyDownEvent') && event.toString().contains('Arrow Up')) {
print(event.toString());
setState(() {
counter--;
}
);
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
}
),],);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。