mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
handle mouse back button event
This commit is contained in:
@@ -21,7 +21,6 @@ import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/foundation/state_controller.dart';
|
||||
import 'package:venera/network/cloudflare.dart';
|
||||
import 'package:venera/pages/comic_page.dart';
|
||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||
@@ -45,4 +44,5 @@ part 'scroll.dart';
|
||||
part 'select.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'comic.dart';
|
||||
part 'effects.dart';
|
||||
part 'effects.dart';
|
||||
part 'gesture.dart';
|
61
lib/components/gesture.dart
Normal file
61
lib/components/gesture.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
part of 'components.dart';
|
||||
|
||||
class MouseBackRecognizer extends BaseTapGestureRecognizer {
|
||||
GestureTapDownCallback? onTapDown;
|
||||
|
||||
MouseBackRecognizer({
|
||||
super.debugOwner,
|
||||
super.supportedDevices,
|
||||
super.allowedButtonsFilter,
|
||||
});
|
||||
|
||||
@override
|
||||
void handleTapCancel({
|
||||
required PointerDownEvent down,
|
||||
PointerCancelEvent? cancel,
|
||||
required String reason,
|
||||
}) {}
|
||||
|
||||
@override
|
||||
void handleTapDown({required PointerDownEvent down}) {
|
||||
final TapDownDetails details = TapDownDetails(
|
||||
globalPosition: down.position,
|
||||
localPosition: down.localPosition,
|
||||
kind: getKindForPointer(down.pointer),
|
||||
);
|
||||
|
||||
if (down.buttons == kBackMouseButton && onTapDown != null) {
|
||||
invokeCallback<void>('onTapDown', () => onTapDown!(details));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleTapUp({
|
||||
required PointerDownEvent down,
|
||||
required PointerUpEvent up,
|
||||
}) {}
|
||||
}
|
||||
|
||||
class MouseBackDetector extends StatelessWidget {
|
||||
const MouseBackDetector({super.key, required this.onTapDown, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
final GestureTapDownCallback onTapDown;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RawGestureDetector(
|
||||
gestures: <Type, GestureRecognizerFactory>{
|
||||
MouseBackRecognizer: GestureRecognizerFactoryWithHandlers<MouseBackRecognizer>(
|
||||
() => MouseBackRecognizer(),
|
||||
(MouseBackRecognizer instance) {
|
||||
instance.onTapDown = onTapDown;
|
||||
},
|
||||
),
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ void main(List<String> args) {
|
||||
runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await init();
|
||||
if(App.isAndroid) {
|
||||
if (App.isAndroid) {
|
||||
handleLinks();
|
||||
}
|
||||
FlutterError.onError = (details) {
|
||||
@@ -73,6 +73,7 @@ class _MyAppState extends State<MyApp> {
|
||||
el.markNeedsBuild();
|
||||
el.visitChildren(rebuild);
|
||||
}
|
||||
|
||||
(context as Element).visitChildren(rebuild);
|
||||
setState(() {});
|
||||
}
|
||||
@@ -114,10 +115,10 @@ class _MyAppState extends State<MyApp> {
|
||||
],
|
||||
locale: () {
|
||||
var lang = appdata.settings['language'];
|
||||
if(lang == 'system') {
|
||||
if (lang == 'system') {
|
||||
return null;
|
||||
}
|
||||
return switch(lang) {
|
||||
return switch (lang) {
|
||||
'zh-CN' => const Locale('zh', 'CN'),
|
||||
'zh-TW' => const Locale('zh', 'TW'),
|
||||
'en-US' => const Locale('en'),
|
||||
@@ -148,7 +149,12 @@ class _MyAppState extends State<MyApp> {
|
||||
App.pop,
|
||||
),
|
||||
},
|
||||
child: WindowFrame(widget),
|
||||
child: MouseBackDetector(
|
||||
onTapDown: (event) {
|
||||
App.pop();
|
||||
},
|
||||
child: WindowFrame(widget),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _SystemUiProvider(Material(
|
||||
|
Reference in New Issue
Block a user