mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
fix: Improve keyboard input handling (#102)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
2038847552
commit
76ac1aaa5b
7 changed files with 584 additions and 571 deletions
35
lib/util/input_handler.dart
Normal file
35
lib/util/input_handler.dart
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class InputHandler extends StatefulWidget {
|
||||
final bool autoFocus;
|
||||
final KeyEventResult Function(FocusNode node, KeyEvent event)? onKeyEvent;
|
||||
final Widget child;
|
||||
const InputHandler({
|
||||
required this.child,
|
||||
this.autoFocus = true,
|
||||
this.onKeyEvent,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<InputHandler> createState() => _InputHandlerState();
|
||||
}
|
||||
|
||||
class _InputHandlerState extends State<InputHandler> {
|
||||
final focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Focus(
|
||||
autofocus: widget.autoFocus,
|
||||
focusNode: focusNode,
|
||||
onFocusChange: (value) {
|
||||
if (!focusNode.hasFocus) {
|
||||
focusNode.requestFocus();
|
||||
}
|
||||
},
|
||||
onKeyEvent: widget.onKeyEvent,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue