Fix backspace delete
This commit is contained in:
@@ -38,9 +38,6 @@ void main() async {
|
||||
class JournalerApp extends StatelessWidget {
|
||||
const JournalerApp({super.key});
|
||||
|
||||
static final GlobalKey<MainPageState> _mainPageKey =
|
||||
GlobalKey<MainPageState>();
|
||||
|
||||
static final TextTheme _baseTextTheme = const TextTheme(
|
||||
bodyMedium: TextStyle(fontSize: 24),
|
||||
);
|
||||
@@ -114,30 +111,7 @@ class JournalerApp extends StatelessWidget {
|
||||
theme: lightTheme,
|
||||
darkTheme: darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
home: Focus(
|
||||
// Using RawKeyboardListener despite deprecation because KeyboardListener
|
||||
// and Shortcuts/Actions didn't reliably capture the Escape key press
|
||||
// before the TextField handled it for unfocusing, requiring two presses.
|
||||
// RawKeyboardListener intercepts the event earlier.
|
||||
child: RawKeyboardListener(
|
||||
// Revert to RawKeyboardListener
|
||||
focusNode: FocusNode(),
|
||||
onKey: (RawKeyEvent event) {
|
||||
// Revert to onKey and RawKeyEvent
|
||||
if (event is RawKeyDownEvent && // Revert to RawKeyDownEvent
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
debugPrint("Escape pressed (RawKeyboardListener - Workaround)");
|
||||
final state = _mainPageKey.currentState;
|
||||
if (state != null) {
|
||||
// Re-add unfocus, as it seemed necessary with Raw listener
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
state.onWindowClose();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: MainPage(key: _mainPageKey),
|
||||
),
|
||||
),
|
||||
home: const MainPage(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
@@ -286,7 +260,21 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
||||
return RawKeyboardListener(
|
||||
focusNode: FocusNode(), // Needs its own node
|
||||
onKey: (RawKeyEvent event) {
|
||||
if (event is RawKeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.escape) {
|
||||
debugPrint(
|
||||
"Escape pressed inside MainPage (RawKeyboardListener - Workaround)",
|
||||
);
|
||||
// Call method directly since we are in the state
|
||||
FocusManager.instance.primaryFocus?.unfocus(); // Keep unfocus attempt
|
||||
onWindowClose();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -348,6 +336,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user