feat: Navigate in image viewer with keyboard keys

This commit is contained in:
krille-chan 2025-02-22 11:23:13 +01:00
commit dfe6717a29
No known key found for this signature in database
2 changed files with 37 additions and 19 deletions

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:matrix/matrix.dart';
@ -26,6 +27,8 @@ class ImageViewer extends StatefulWidget {
}
class ImageViewerController extends State<ImageViewer> {
final FocusNode focusNode = FocusNode();
@override
void initState() {
super.initState();
@ -45,6 +48,17 @@ class ImageViewerController extends State<ImageViewer> {
late final List<Event> allEvents;
void onKeyEvent(KeyEvent event) {
switch (event.logicalKey) {
case LogicalKeyboardKey.arrowLeft:
if (canGoBack) prevImage();
break;
case LogicalKeyboardKey.arrowRight:
if (canGoNext) nextImage();
break;
}
}
void prevImage() async {
await pageController.previousPage(
duration: FluffyThemes.animationDuration,