Im creating a flutter desktop app and keyboard events are not being detected by the FocusScope
in Release mode. Everything works fine in debug mode. Any idea how I can get this working right?
Maybe I can give my client the debug folder since it works fine, and not the Release. Are there any significant differences besides size? I cant seem to identify anything noticeable as both versions load fast.
My code below:
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;
}
),
],
),
),
);
}
}