11import 'package:flutter/gestures.dart' ;
22import 'package:flutter/material.dart' ;
33import 'package:flutter_hooks/flutter_hooks.dart' ;
4+ import 'package:flutter_volume_controller/flutter_volume_controller.dart' ;
45import 'package:iris/globals.dart' show speedStops, speedSelectorItemWidth;
56import 'package:iris/hooks/use_brightness.dart' ;
67import 'package:iris/hooks/use_volume.dart' ;
@@ -31,7 +32,6 @@ class Gesture {
3132 final bool isRightGesture;
3233 final double ? brightness;
3334 final double ? volume;
34- final MouseCursor cursor;
3535
3636 Gesture ({
3737 required this .onTapDown,
@@ -51,7 +51,6 @@ class Gesture {
5151 required this .isRightGesture,
5252 required this .brightness,
5353 required this .volume,
54- required this .cursor,
5554 });
5655}
5756
@@ -65,8 +64,6 @@ Gesture useGesture({
6564}) {
6665 final context = useContext ();
6766
68- final player = context.read <MediaPlayer >();
69-
7067 final gestureState = useRef ({
7168 'isTouch' : false ,
7269 'isLongPress' : false ,
@@ -97,20 +94,22 @@ Gesture useGesture({
9794 }
9895
9996 void onDoubleTapDown (TapDownDetails details) {
97+ final player = context.read <MediaPlayer >();
98+
10099 if (details.kind == PointerDeviceKind .touch) {
101100 final screenWidth = MediaQuery .sizeOf (context).width;
102101 final tapDx = details.globalPosition.dx;
103102
104- if (tapDx > screenWidth * 0.7 ) {
105- // 右侧 30 %
103+ if (tapDx > screenWidth * 0.75 ) {
104+ // 右侧 25 %
106105 showProgress ();
107106 player.forward (10 );
108- } else if (tapDx < screenWidth * 0.3 ) {
109- // 左侧 30 %
107+ } else if (tapDx < screenWidth * 0.25 ) {
108+ // 左侧 25 %
110109 showProgress ();
111110 player.backward (10 );
112111 } else {
113- // 中间 40 %
112+ // 中间 50 %
114113 if (player.isPlaying) {
115114 useAppStore ().updateAutoPlay (false );
116115 player.pause ();
@@ -128,7 +127,8 @@ Gesture useGesture({
128127 }
129128
130129 void onLongPressStart (LongPressStartDetails details) {
131- if (gestureState.value['isTouch' ] as bool && player.isPlaying) {
130+ if (gestureState.value['isTouch' ] as bool &&
131+ context.read <MediaPlayer >().isPlaying) {
132132 gestureState.value['isLongPress' ] = true ;
133133 gestureState.value['startPanOffset' ] = details.globalPosition;
134134
@@ -206,7 +206,8 @@ Gesture useGesture({
206206 gestureState.value['isTouch' ] = true ;
207207 gestureState.value['isDragging' ] = true ;
208208 gestureState.value['startPanOffset' ] = details.globalPosition;
209- gestureState.value['startSeekPosition' ] = player.position;
209+ gestureState.value['startSeekPosition' ] =
210+ context.read <MediaPlayer >().position;
210211 gestureState.value['panDirection' ] = null ;
211212 isLeftGesture.value = false ;
212213 isRightGesture.value = false ;
@@ -246,9 +247,10 @@ Gesture useGesture({
246247 int targetSeconds = (startSeconds + seekSecondsOffset).round ();
247248
248249 // 边界检查
249- targetSeconds = targetSeconds.clamp (0 , player.duration.inSeconds);
250+ targetSeconds = targetSeconds.clamp (
251+ 0 , context.read <MediaPlayer >().duration.inSeconds);
250252
251- player .seek (Duration (seconds: targetSeconds));
253+ context. read < MediaPlayer >() .seek (Duration (seconds: targetSeconds));
252254 showProgress ();
253255 }
254256
@@ -259,6 +261,10 @@ Gesture useGesture({
259261 isLeftGesture.value =
260262 startOffset.dx < MediaQuery .sizeOf (context).width / 2 ;
261263 isRightGesture.value = ! isLeftGesture.value;
264+
265+ if (isRightGesture.value) {
266+ FlutterVolumeController .updateShowSystemUI (false );
267+ }
262268 }
263269
264270 final double dy = details.delta.dy;
@@ -287,6 +293,8 @@ Gesture useGesture({
287293 };
288294 isLeftGesture.value = false ;
289295 isRightGesture.value = false ;
296+
297+ FlutterVolumeController .updateShowSystemUI (true );
290298 }
291299
292300 void onPanEnd (DragEndDetails details) => _resetPanState ();
@@ -299,12 +307,6 @@ Gesture useGesture({
299307 }
300308 }
301309
302- final cursor = useMemoized (() {
303- return player.isPlaying == false
304- ? SystemMouseCursors .basic
305- : SystemMouseCursors .none;
306- }, [player.isPlaying]);
307-
308310 return Gesture (
309311 onTapDown: onTapDown,
310312 onTap: onTap,
@@ -323,6 +325,5 @@ Gesture useGesture({
323325 isRightGesture: isRightGesture.value,
324326 brightness: brightness.value,
325327 volume: volume.value,
326- cursor: cursor,
327328 );
328329}
0 commit comments