Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-01-22 15:51:22 +08:00
parent 92e5fae29c
commit b9b54ce4f7
34 changed files with 627 additions and 665 deletions

View File

@@ -0,0 +1,42 @@
import 'package:flutter/gestures.dart' show kBackMouseButton;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show KeyDownEvent;
class BackDetector extends StatelessWidget {
const BackDetector({
super.key,
required this.onBack,
required this.child,
});
final Widget child;
final VoidCallback onBack;
@override
Widget build(BuildContext context) {
return Focus(
canRequestFocus: false,
onKeyEvent: _onKeyEvent,
child: Listener(
behavior: .translucent,
onPointerDown: _onPointerDown,
child: child,
),
);
}
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
if (event.logicalKey == .escape && event is KeyDownEvent) {
onBack();
return .handled;
}
return .ignored;
}
void _onPointerDown(PointerDownEvent event) {
if (event.buttons == kBackMouseButton) {
onBack();
}
}
}

View File

@@ -34,6 +34,9 @@ class _CustomTooltipState extends State<CustomTooltip> {
final OverlayPortalController _overlayController = OverlayPortalController();
LongPressGestureRecognizer? _longPressRecognizer;
LongPressGestureRecognizer get longPressRecognizer =>
_longPressRecognizer ??= LongPressGestureRecognizer()
..onLongPress = _scheduleShowTooltip;
void _scheduleShowTooltip() {
_overlayController.show();
@@ -45,9 +48,7 @@ class _CustomTooltipState extends State<CustomTooltip> {
void _handlePointerDown(PointerDownEvent event) {
assert(mounted);
(_longPressRecognizer ??= LongPressGestureRecognizer(
debugOwner: this,
)..onLongPress = _scheduleShowTooltip).addPointer(event);
longPressRecognizer.addPointer(event);
}
Widget _buildCustomTooltipOverlay(BuildContext context) {
@@ -80,7 +81,7 @@ class _CustomTooltipState extends State<CustomTooltip> {
@override
void dispose() {
_longPressRecognizer
?..onLongPressCancel = null
?..onLongPress = null
..dispose();
_longPressRecognizer = null;
super.dispose();

View File

@@ -0,0 +1,44 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
abstract class PopScopeState<T extends StatefulWidget> extends State<T>
implements PopEntry<T> {
ModalRoute<dynamic>? _route;
@override
void onPopInvoked(bool didPop) {}
@override
late final ValueNotifier<bool> canPopNotifier;
void initCanPopNotifier() {
canPopNotifier = ValueNotifier<bool>(false);
}
@override
void initState() {
super.initState();
initCanPopNotifier();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final ModalRoute<dynamic>? nextRoute = ModalRoute.of(context);
if (nextRoute != _route) {
_route?.unregisterPopEntry(this);
_route = nextRoute;
_route?.registerPopEntry(this);
}
}
@override
void dispose() {
_route?.unregisterPopEntry(this);
canPopNotifier.dispose();
super.dispose();
}
}

View File

@@ -1,27 +0,0 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class MouseBackDetector extends StatelessWidget {
const MouseBackDetector({
super.key,
required this.onTapDown,
required this.child,
});
final Widget child;
final VoidCallback onTapDown;
@override
Widget build(BuildContext context) {
return Listener(
onPointerDown: (event) {
if (event.buttons == kBackMouseButton) {
onTapDown();
}
},
behavior: HitTestBehavior.translucent,
child: child,
);
}
}

View File

@@ -0,0 +1,25 @@
import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/material.dart';
class CustomScrollBehavior extends MaterialScrollBehavior {
const CustomScrollBehavior(this.dragDevices);
@override
Widget buildScrollbar(
BuildContext context,
Widget child,
ScrollableDetails details,
) => child;
@override
final Set<PointerDeviceKind> dragDevices;
}
const Set<PointerDeviceKind> desktopDragDevices = <PointerDeviceKind>{
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
PointerDeviceKind.trackpad,
PointerDeviceKind.unknown,
PointerDeviceKind.mouse,
};