fix: restore hardware key focus after lock/unlock in boxing screen
Add WidgetsBindingObserver lifecycle hook to re-request focus when app resumes, fixing P2 key not working after screen lock.
This commit is contained in:
@@ -83,7 +83,7 @@ class BoxingPage extends StatefulWidget {
|
||||
State<BoxingPage> createState() => _BoxingPageState();
|
||||
}
|
||||
|
||||
class _BoxingPageState extends State<BoxingPage> {
|
||||
class _BoxingPageState extends State<BoxingPage> with WidgetsBindingObserver {
|
||||
static const _androidKeyCodeButtonR1 = 103;
|
||||
|
||||
final _scannerService = ScannerService();
|
||||
@@ -147,6 +147,7 @@ class _BoxingPageState extends State<BoxingPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
final arguments = widget.arguments;
|
||||
if (arguments != null) {
|
||||
_mode = arguments.initialMode;
|
||||
@@ -163,6 +164,7 @@ class _BoxingPageState extends State<BoxingPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_boxNoController.removeListener(_onBoxNoTextChanged);
|
||||
_scanSubscription?.cancel();
|
||||
_focusNode.dispose();
|
||||
@@ -180,6 +182,13 @@ class _BoxingPageState extends State<BoxingPage> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void _onKeyEvent(KeyEvent event) {
|
||||
if (event is! KeyDownEvent || _isAutoProcessing) return;
|
||||
if (_isModeSwitchKey(event)) {
|
||||
|
||||
Reference in New Issue
Block a user