added keyboard input

main
Kaj Rusilowski 2024-04-09 21:39:59 +02:00
parent 7880da056a
commit 5d5ae63c16
1 changed files with 22 additions and 13 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -51,24 +52,32 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: RawKeyboardListener(
child: Column( focusNode: FocusNode(),
mainAxisAlignment: MainAxisAlignment.center, autofocus: true,
children: <Widget>[ onKey: (RawKeyEvent event) {
const Text( if (event.isKeyPressed(LogicalKeyboardKey.keyD)) _decrementCounter();
'You have pushed the button this many times:', if (event.isKeyPressed(LogicalKeyboardKey.keyI)) _incrementCounter();
), },
Text( child: Center(
'$_counter', child: Column(
style: Theme.of(context).textTheme.headlineMedium, mainAxisAlignment: MainAxisAlignment.center,
), children: <Widget>[
], const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
), ),
), ),
floatingActionButton: Stack( floatingActionButton: Stack(
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: EdgeInsets.only(left: 31), padding: const EdgeInsets.only(left: 31),
child: Align( child: Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: FloatingActionButton( child: FloatingActionButton(