TF-2764 Support press Escape shortcut key on keyboard to close viewer

This commit is contained in:
dab246
2024-05-22 16:32:40 +07:00
committed by Dat H. Pham
parent 9351ebfd33
commit 652f15e356
2 changed files with 160 additions and 144 deletions
@@ -60,6 +60,7 @@ class _PDFViewerState extends State<PDFViewer> {
final ValueNotifier<Object?> _pdfViewStateNotifier = ValueNotifier<Object?>(null);
final DeviceInfoPlugin _deviceInfoPlugin = Get.find<DeviceInfoPlugin>();
final FocusNode _keyboardFocusNode = FocusNode();
@override
void initState() {
@@ -116,12 +117,17 @@ class _PDFViewerState extends State<PDFViewer> {
_downloadInteractorStreamSubscription?.cancel();
_downloadInteractorStreamSubscription = null;
_downloadAttachmentCancelToken = null;
_keyboardFocusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
return RawKeyboardListener(
focusNode: _keyboardFocusNode,
autofocus: true,
onKey: _handleKeyboardEventListener,
child: Center(
child: Stack(
children: [
Center(
@@ -272,6 +278,7 @@ class _PDFViewerState extends State<PDFViewer> {
),
],
),
),
);
}
@@ -279,4 +286,10 @@ class _PDFViewerState extends State<PDFViewer> {
_downloadAttachmentCancelToken?.cancel();
Navigator.maybeOf(context)?.pop();
}
void _handleKeyboardEventListener(RawKeyEvent event) {
if (event is RawKeyDownEvent && event.logicalKey == LogicalKeyboardKey.escape) {
_closeView();
}
}
}
@@ -8,6 +8,9 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/capability/calendar_event_capability.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';