mirror of
https://github.com/gskinnerTeam/flutter-wonderous-app.git
synced 2025-08-06 18:24:29 +08:00
TrackpadListener functional in Photo Gallery (for testing). Will apply elsewhere.
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
|
||||
class TrackpadReader extends StatefulWidget {
|
||||
class TrackpadListener extends StatefulWidget {
|
||||
static const int swipeSensitivity = 15;
|
||||
static const int scrollSensitivity = 100;
|
||||
|
||||
const TrackpadReader({
|
||||
const TrackpadListener({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.swipeUp,
|
||||
@ -29,30 +29,21 @@ class TrackpadReader extends StatefulWidget {
|
||||
final void Function()? scrollRight;
|
||||
|
||||
@override
|
||||
State<TrackpadReader> createState() => _TrackpadReaderState();
|
||||
State<TrackpadListener> createState() => _TrackpadListenerState();
|
||||
}
|
||||
|
||||
class _TrackpadReaderState extends State<TrackpadReader> {
|
||||
class _TrackpadListenerState extends State<TrackpadListener> {
|
||||
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) {
|
||||
if (event.scrollDelta.dy > TrackpadListener.swipeSensitivity) {
|
||||
widget.swipeDown?.call();
|
||||
} else if (event.scrollDelta.dy < -TrackpadListener.swipeSensitivity) {
|
||||
widget.swipeUp?.call();
|
||||
}
|
||||
if (event.scrollDelta.dx > TrackpadReader.swipeSensitivity) {
|
||||
if (event.scrollDelta.dx > TrackpadListener.swipeSensitivity) {
|
||||
widget.swipeLeft?.call();
|
||||
} else if (event.scrollDelta.dx < TrackpadReader.swipeSensitivity) {
|
||||
} else if (event.scrollDelta.dx < -TrackpadListener.swipeSensitivity) {
|
||||
widget.swipeRight?.call();
|
||||
}
|
||||
}
|
@ -5,7 +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/controls/trackpad_listener.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';
|
||||
@ -170,11 +170,23 @@ class _PhotoGalleryState extends State<PhotoGallery> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TrackpadReader(
|
||||
swipeLeft: () => _handleSwipe(Offset(-1, 0)),
|
||||
swipeRight: () => _handleSwipe(Offset(1, 0)),
|
||||
swipeDown: () => _handleSwipe(Offset(0, -1)),
|
||||
swipeUp: () => _handleSwipe(Offset(0, 1)),
|
||||
return TrackpadListener(
|
||||
swipeLeft: () {
|
||||
debugPrint('LEFT!');
|
||||
_handleSwipe(Offset(-1, 0));
|
||||
},
|
||||
swipeRight: () {
|
||||
debugPrint('RIGHT!');
|
||||
_handleSwipe(Offset(1, 0));
|
||||
},
|
||||
swipeDown: () {
|
||||
debugPrint('DOWN!');
|
||||
_handleSwipe(Offset(0, -1));
|
||||
},
|
||||
swipeUp: () {
|
||||
debugPrint('UP!');
|
||||
_handleSwipe(Offset(0, 1));
|
||||
},
|
||||
child: FullscreenKeyboardListener(
|
||||
onKeyDown: _handleKeyDown,
|
||||
child: ValueListenableBuilder<List<String>>(
|
||||
|
Reference in New Issue
Block a user