Got hiding when tapped working
This commit is contained in:
@@ -56,13 +56,6 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
|
|||||||
(_, state) {
|
(_, state) {
|
||||||
// Show buffering
|
// Show buffering
|
||||||
showBuffering.value = state == VideoPlaybackState.buffering;
|
showBuffering.value = state == VideoPlaybackState.buffering;
|
||||||
|
|
||||||
// Synchronize player with video state
|
|
||||||
if (state == VideoPlaybackState.playing) {
|
|
||||||
ref.read(videoPlayerControlsProvider.notifier).play();
|
|
||||||
} else if (state == VideoPlaybackState.paused) {
|
|
||||||
ref.read(videoPlayerControlsProvider.notifier).pause();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Toggles between playing and pausing depending on the state of the video
|
/// Toggles between playing and pausing depending on the state of the video
|
||||||
@@ -72,6 +65,7 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
onTap: showControlsAndStartHideTimer,
|
onTap: showControlsAndStartHideTimer,
|
||||||
child: AbsorbPointer(
|
child: AbsorbPointer(
|
||||||
absorbing: !ref.watch(showControlsProvider),
|
absorbing: !ref.watch(showControlsProvider),
|
||||||
@@ -82,22 +76,24 @@ class CustomVideoPlayerControls extends HookConsumerWidget {
|
|||||||
child: DelayedLoadingIndicator(
|
child: DelayedLoadingIndicator(
|
||||||
fadeInDuration: Duration(milliseconds: 400),
|
fadeInDuration: Duration(milliseconds: 400),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (state != VideoPlaybackState.playing) {
|
||||||
|
togglePlay();
|
||||||
|
}
|
||||||
|
ref.read(showControlsProvider.notifier).show = false;
|
||||||
|
},
|
||||||
|
child: CenterPlayButton(
|
||||||
|
backgroundColor: Colors.black54,
|
||||||
|
iconColor: Colors.white,
|
||||||
|
isFinished: state == VideoPlaybackState.completed,
|
||||||
|
isPlaying: state == VideoPlaybackState.playing,
|
||||||
|
show: ref.watch(showControlsProvider),
|
||||||
|
onPressed: togglePlay,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
if (state != VideoPlaybackState.playing) {
|
|
||||||
togglePlay();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: CenterPlayButton(
|
|
||||||
backgroundColor: Colors.black54,
|
|
||||||
iconColor: Colors.white,
|
|
||||||
isFinished: state == VideoPlaybackState.completed,
|
|
||||||
isPlaying: state == VideoPlaybackState.playing,
|
|
||||||
show: ref.watch(showControlsProvider),
|
|
||||||
onPressed: togglePlay,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -102,15 +102,6 @@ class VideoViewerPage extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the controls when we load
|
|
||||||
useEffect(
|
|
||||||
() {
|
|
||||||
ref.read(showControlsProvider.notifier).show = false;
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Adds and removes the listener to the video player
|
// Adds and removes the listener to the video player
|
||||||
useEffect(
|
useEffect(
|
||||||
() {
|
() {
|
||||||
@@ -135,46 +126,39 @@ class VideoViewerPage extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final size = MediaQuery.of(context).size;
|
final size = MediaQuery.of(context).size;
|
||||||
return GestureDetector(
|
return PopScope(
|
||||||
onTap: () {
|
onPopInvoked: (pop) {
|
||||||
if (ref.read(showControlsProvider)) {
|
ref.read(videoPlaybackValueProvider.notifier).value =
|
||||||
ref.read(showControlsProvider.notifier).show = false;
|
VideoPlaybackValue.uninitialized();
|
||||||
}
|
|
||||||
},
|
},
|
||||||
child: PopScope(
|
child: AnimatedSwitcher(
|
||||||
onPopInvoked: (pop) {
|
duration: const Duration(milliseconds: 400),
|
||||||
ref.read(videoPlaybackValueProvider.notifier).value =
|
child: Stack(
|
||||||
VideoPlaybackValue.uninitialized();
|
children: [
|
||||||
},
|
Visibility(
|
||||||
child: AnimatedSwitcher(
|
visible: controller == null,
|
||||||
duration: const Duration(milliseconds: 400),
|
child: Stack(
|
||||||
child: Stack(
|
children: [
|
||||||
children: [
|
if (placeholder != null) placeholder!,
|
||||||
Visibility(
|
const Positioned.fill(
|
||||||
visible: controller == null,
|
child: Center(
|
||||||
child: Stack(
|
child: DelayedLoadingIndicator(
|
||||||
children: [
|
fadeInDuration: Duration(milliseconds: 500),
|
||||||
if (placeholder != null) placeholder!,
|
|
||||||
const Positioned.fill(
|
|
||||||
child: Center(
|
|
||||||
child: DelayedLoadingIndicator(
|
|
||||||
fadeInDuration: Duration(milliseconds: 500),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (controller != null)
|
||||||
|
SizedBox(
|
||||||
|
height: size.height,
|
||||||
|
width: size.width,
|
||||||
|
child: Chewie(
|
||||||
|
controller: controller,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (controller != null)
|
],
|
||||||
SizedBox(
|
|
||||||
height: size.height,
|
|
||||||
width: size.width,
|
|
||||||
child: Chewie(
|
|
||||||
controller: controller,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user