Last active
June 29, 2019 22:49
-
-
Save mjeffw/8f3f57d23b596fde3c1a8dac93a64549 to your computer and use it in GitHub Desktop.
Flutter [Web] RawKeyboardListener does not return correct data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_web/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'Hello, World!', | |
), | |
RawKeyboardListener( | |
child: TextField( | |
controller: TextEditingController(text: 'test'), | |
), | |
focusNode: FocusNode(), | |
onKey: (RawKeyEvent value) { | |
print(value.logicalKey); | |
if (value.logicalKey == LogicalKeyboardKey.tab) print('tab'); | |
if (value.logicalKey == LogicalKeyboardKey.keyA) print('A'); | |
}, | |
), | |
], | |
), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment