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