Fix deprecated keyboard controller
This commit is contained in:
@@ -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,8 +106,8 @@ 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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
Reference in New Issue
Block a user