Fix deprecated keyboard controller

This commit is contained in:
2025-03-15 00:00:51 +01:00
parent 8640ad0499
commit a29f090895

View File

@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:io';
import 'dart:convert';
import 'dart:developer' as developer;
void main() {
runApp(const MyApp());
@@ -81,8 +82,8 @@ class _MyHomePageState extends State<MyHomePage> {
};
await file.writeAsString(jsonEncode(data));
} catch (e) {
// Handle error silently for simplicity
print('Failed to save timer data: $e');
// Handle error silently using proper logging
developer.log('Failed to save timer data: $e', name: 'simple_timer');
}
}
@@ -105,10 +106,10 @@ class _MyHomePageState extends State<MyHomePage> {
_reconstructTimerState();
}
} catch (e) {
// Handle error silently for simplicity
print('Failed to load timer data: $e');
}
// Handle error silently using proper logging
developer.log('Failed to load timer data: $e', name: 'simple_timer');
}
}
void _reconstructTimerState() {
if (_events.isEmpty) return;
@@ -297,8 +298,8 @@ class _MyHomePageState extends State<MyHomePage> {
return _formatDuration(duration);
}
void _handleKeyEvent(RawKeyEvent event) {
if (event is RawKeyDownEvent) {
void _handleKeyEvent(KeyEvent event) {
if (event is KeyDownEvent) {
if (event.logicalKey == LogicalKeyboardKey.space) {
// Space: Start if paused, Lap if running
if (_isRunning) {
@@ -326,9 +327,9 @@ class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return RawKeyboardListener(
return KeyboardListener(
focusNode: _focusNode,
onKey: _handleKeyEvent,
onKeyEvent: _handleKeyEvent,
autofocus: true,
child: Scaffold(
appBar: AppBar(