@@ -32,7 +32,6 @@ class Gesture {
3232 final bool isRightGesture;
3333 final double ? brightness;
3434 final double ? volume;
35- final MouseCursor cursor;
3635
3736 Gesture ({
3837 required this .onTapDown,
@@ -52,7 +51,6 @@ class Gesture {
5251 required this .isRightGesture,
5352 required this .brightness,
5453 required this .volume,
55- required this .cursor,
5654 });
5755}
5856
@@ -66,8 +64,6 @@ Gesture useGesture({
6664}) {
6765 final context = useContext ();
6866
69- final player = context.read <MediaPlayer >();
70-
7167 final gestureState = useRef ({
7268 'isTouch' : false ,
7369 'isLongPress' : false ,
@@ -98,6 +94,8 @@ Gesture useGesture({
9894 }
9995
10096 void onDoubleTapDown (TapDownDetails details) {
97+ final player = context.read <MediaPlayer >();
98+
10199 if (details.kind == PointerDeviceKind .touch) {
102100 final screenWidth = MediaQuery .sizeOf (context).width;
103101 final tapDx = details.globalPosition.dx;
@@ -129,7 +127,8 @@ Gesture useGesture({
129127 }
130128
131129 void onLongPressStart (LongPressStartDetails details) {
132- if (gestureState.value['isTouch' ] as bool && player.isPlaying) {
130+ if (gestureState.value['isTouch' ] as bool &&
131+ context.read <MediaPlayer >().isPlaying) {
133132 gestureState.value['isLongPress' ] = true ;
134133 gestureState.value['startPanOffset' ] = details.globalPosition;
135134
@@ -207,7 +206,8 @@ Gesture useGesture({
207206 gestureState.value['isTouch' ] = true ;
208207 gestureState.value['isDragging' ] = true ;
209208 gestureState.value['startPanOffset' ] = details.globalPosition;
210- gestureState.value['startSeekPosition' ] = player.position;
209+ gestureState.value['startSeekPosition' ] =
210+ context.read <MediaPlayer >().position;
211211 gestureState.value['panDirection' ] = null ;
212212 isLeftGesture.value = false ;
213213 isRightGesture.value = false ;
@@ -247,9 +247,10 @@ Gesture useGesture({
247247 int targetSeconds = (startSeconds + seekSecondsOffset).round ();
248248
249249 // 边界检查
250- targetSeconds = targetSeconds.clamp (0 , player.duration.inSeconds);
250+ targetSeconds = targetSeconds.clamp (
251+ 0 , context.read <MediaPlayer >().duration.inSeconds);
251252
252- player .seek (Duration (seconds: targetSeconds));
253+ context. read < MediaPlayer >() .seek (Duration (seconds: targetSeconds));
253254 showProgress ();
254255 }
255256
@@ -306,12 +307,6 @@ Gesture useGesture({
306307 }
307308 }
308309
309- final cursor = useMemoized (() {
310- return player.isPlaying == false
311- ? SystemMouseCursors .basic
312- : SystemMouseCursors .none;
313- }, [player.isPlaying]);
314-
315310 return Gesture (
316311 onTapDown: onTapDown,
317312 onTap: onTap,
@@ -330,6 +325,5 @@ Gesture useGesture({
330325 isRightGesture: isRightGesture.value,
331326 brightness: brightness.value,
332327 volume: volume.value,
333- cursor: cursor,
334328 );
335329}
0 commit comments