Files
imajviewer/lib/shortcuts/app_shortcuts.dart
T
Alhan 35ac949f4e
Build Windows / build-windows (push) Has been cancelled
fix: ok tuşları + buton hover/siyah border + çift tıklama cover
2026-07-22 05:20:07 +03:00

63 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import '../services/image_manager.dart';
import '../services/file_handler.dart';
class AppShortcuts extends StatelessWidget {
final Widget child;
const AppShortcuts({super.key, required this.child});
@override
Widget build(BuildContext context) {
return Focus(
autofocus: true,
onKeyEvent: (node, event) {
if (event is KeyDownEvent) {
switch (event.logicalKey) {
case LogicalKeyboardKey.arrowLeft:
ImageManager.instance.previousImage();
return KeyEventResult.handled;
case LogicalKeyboardKey.arrowRight:
ImageManager.instance.nextImage();
return KeyEventResult.handled;
case LogicalKeyboardKey.escape:
windowManager.isFullScreen().then((isFullscreen) {
if (isFullscreen) windowManager.setFullScreen(false);
});
return KeyEventResult.handled;
}
}
return KeyEventResult.ignored;
},
child: CallbackShortcuts(
bindings: {
// Open file dialog
const SingleActivator(
LogicalKeyboardKey.keyO,
control: true,
): () {
FileHandler.openFileDialog();
},
// Fullscreen toggle
const SingleActivator(LogicalKeyboardKey.f11): () async {
final isFullscreen = await windowManager.isFullScreen();
await windowManager.setFullScreen(!isFullscreen);
},
// Quit
const SingleActivator(
LogicalKeyboardKey.keyQ,
control: true,
): () {
windowManager.close();
},
},
child: child,
),
);
}
}