mirror of
https://github.com/gskinnerTeam/flutter-wonderous-app.git
synced 2025-08-06 18:24:29 +08:00
Creating a Trackpad reader to cover bases.
This commit is contained in:
74
lib/ui/common/controls/trackpad_reader.dart
Normal file
74
lib/ui/common/controls/trackpad_reader.dart
Normal file
@ -0,0 +1,74 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
|
||||
class TrackpadReader extends StatefulWidget {
|
||||
static const int swipeSensitivity = 15;
|
||||
static const int scrollSensitivity = 100;
|
||||
|
||||
const TrackpadReader({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.swipeUp,
|
||||
this.swipeDown,
|
||||
this.swipeLeft,
|
||||
this.swipeRight,
|
||||
this.scrollUp,
|
||||
this.scrollDown,
|
||||
this.scrollLeft,
|
||||
this.scrollRight,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final void Function()? swipeUp;
|
||||
final void Function()? swipeDown;
|
||||
final void Function()? swipeLeft;
|
||||
final void Function()? swipeRight;
|
||||
final void Function()? scrollUp;
|
||||
final void Function()? scrollDown;
|
||||
final void Function()? scrollLeft;
|
||||
final void Function()? scrollRight;
|
||||
|
||||
@override
|
||||
State<TrackpadReader> createState() => _TrackpadReaderState();
|
||||
}
|
||||
|
||||
class _TrackpadReaderState extends State<TrackpadReader> {
|
||||
void _handleTrackpadEvent(PointerSignalEvent event) {
|
||||
GestureBinding.instance.pointerSignalResolver.register(event, (PointerSignalEvent event) {
|
||||
if (event is PointerScrollEvent && event.kind == PointerDeviceKind.trackpad) {
|
||||
debugPrint(' - TrackpadReader: ${event}');
|
||||
debugPrint(' - TrackpadReader A: ${event.scrollDelta}');
|
||||
debugPrint(' - TrackpadReader B: ${event.platformData}');
|
||||
debugPrint(' - TrackpadReader C: ${event.buttons}');
|
||||
debugPrint(' - TrackpadReader D: ${event.delta}');
|
||||
debugPrint(' - TrackpadReader E: ${event.device}');
|
||||
debugPrint(' - TrackpadReader F: ${event.kind}');
|
||||
debugPrint(' - TrackpadReader G: ${event.timeStamp}');
|
||||
debugPrint(' - TrackpadReader H: ${event.size}');
|
||||
if (event.scrollDelta.dy > TrackpadReader.swipeSensitivity) {
|
||||
widget.swipeUp?.call();
|
||||
} else if (event.scrollDelta.dy < TrackpadReader.swipeSensitivity) {
|
||||
widget.swipeDown?.call();
|
||||
}
|
||||
if (event.scrollDelta.dx > TrackpadReader.swipeSensitivity) {
|
||||
widget.swipeLeft?.call();
|
||||
} else if (event.scrollDelta.dx < TrackpadReader.swipeSensitivity) {
|
||||
widget.swipeRight?.call();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Listener(
|
||||
onPointerPanZoomStart: (event) {
|
||||
debugPrint(' - TrackpadReader: onPointerPanZoomStart');
|
||||
},
|
||||
onPointerPanZoomEnd: (event) {
|
||||
debugPrint(' - TrackpadReader: onPointerPanZoomEnd');
|
||||
},
|
||||
onPointerSignal: _handleTrackpadEvent,
|
||||
child: widget.child);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import 'package:wonders/common_libs.dart';
|
||||
import 'package:wonders/logic/data/unsplash_photo_data.dart';
|
||||
import 'package:wonders/ui/common/controls/app_loading_indicator.dart';
|
||||
import 'package:wonders/ui/common/controls/eight_way_swipe_detector.dart';
|
||||
import 'package:wonders/ui/common/controls/trackpad_reader.dart';
|
||||
import 'package:wonders/ui/common/fullscreen_keyboard_listener.dart';
|
||||
import 'package:wonders/ui/common/hidden_collectible.dart';
|
||||
import 'package:wonders/ui/common/ignore_pointer.dart';
|
||||
@ -169,9 +170,14 @@ class _PhotoGalleryState extends State<PhotoGallery> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FullscreenKeyboardListener(
|
||||
onKeyDown: _handleKeyDown,
|
||||
child: ValueListenableBuilder<List<String>>(
|
||||
return TrackpadReader(
|
||||
swipeLeft: () => _handleSwipe(Offset(-1, 0)),
|
||||
swipeRight: () => _handleSwipe(Offset(1, 0)),
|
||||
swipeDown: () => _handleSwipe(Offset(0, -1)),
|
||||
swipeUp: () => _handleSwipe(Offset(0, 1)),
|
||||
child: FullscreenKeyboardListener(
|
||||
onKeyDown: _handleKeyDown,
|
||||
child: ValueListenableBuilder<List<String>>(
|
||||
valueListenable: _photoIds,
|
||||
builder: (_, value, __) {
|
||||
if (value.isEmpty) {
|
||||
@ -227,7 +233,9 @@ class _PhotoGalleryState extends State<PhotoGallery> {
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user