Migrate RawKeyboardListener to KeyboardListener

This commit is contained in:
Ming Ming 2024-09-19 22:33:30 +08:00
parent 88bfeec40b
commit f2308abf84
2 changed files with 22 additions and 9 deletions

View file

@ -67,16 +67,18 @@ class _HorizontalPageViewerState extends State<HorizontalPageViewer> {
Widget _buildWebContent(BuildContext context) {
assert(getRawPlatform() == NpPlatform.web);
// support switching pages with keyboard on web
return RawKeyboardListener(
onKey: (ev) {
return KeyboardListener(
onKeyEvent: (ev) {
if (!widget.canSwitchPage) {
return;
}
if (ev.isKeyPressed(LogicalKeyboardKey.arrowLeft)) {
if (ev is KeyUpEvent) {
if (ev.logicalKey == LogicalKeyboardKey.arrowLeft) {
_switchToLeft();
} else if (ev.isKeyPressed(LogicalKeyboardKey.arrowRight)) {
} else if (ev.logicalKey == LogicalKeyboardKey.arrowRight) {
_switchToRight();
}
}
},
focusNode: _pageFocus,
child: _buildContent(context),

View file

@ -2,6 +2,7 @@ import 'dart:math' as math;
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/app_localizations.dart';
@ -80,9 +81,19 @@ class _SelectableItemListState<T extends SelectableItemMetadata>
Widget build(BuildContext context) {
if (getRawPlatform() == NpPlatform.web) {
// support shift+click group selection on web
return RawKeyboardListener(
onKey: (ev) {
_isKeyboardRangeSelecting = ev.isShiftPressed;
return KeyboardListener(
onKeyEvent: (ev) {
if (ev is KeyDownEvent) {
if (ev.logicalKey == LogicalKeyboardKey.shiftLeft ||
ev.logicalKey == LogicalKeyboardKey.shiftRight) {
_isKeyboardRangeSelecting = true;
}
} else if (ev is KeyUpEvent) {
if (ev.logicalKey == LogicalKeyboardKey.shiftLeft ||
ev.logicalKey == LogicalKeyboardKey.shiftRight) {
_isKeyboardRangeSelecting = false;
}
}
},
focusNode: _keyboardFocus,
child: _buildBody(context),