Skip to content

Commit d58b737

Browse files
committed
Refactor un needed set states, refactor play if finished( as video player restarts if finished)
1 parent 4406b0e commit d58b737

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

lib/src/material/material_desktop_controls.dart

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -485,40 +485,37 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
485485
void _onExpandCollapse() {
486486
setState(() {
487487
notifier.hideStuff = true;
488+
});
488489

489-
chewieController.toggleFullScreen();
490-
_showAfterExpandCollapseTimer =
491-
Timer(const Duration(milliseconds: 300), () {
492-
setState(() {
493-
_cancelAndRestartTimer();
494-
});
490+
chewieController.toggleFullScreen();
491+
492+
_showAfterExpandCollapseTimer =
493+
Timer(const Duration(milliseconds: 300), () {
494+
setState(() {
495+
_cancelAndRestartTimer();
495496
});
496497
});
497498
}
498499

499500
void _playPause() {
500-
final isFinished = _latestValue.position >= _latestValue.duration;
501-
502-
setState(() {
503-
if (controller.value.isPlaying) {
501+
if (controller.value.isPlaying) {
502+
setState(() {
504503
notifier.hideStuff = false;
505-
_hideTimer?.cancel();
506-
controller.pause();
507-
} else {
508-
_cancelAndRestartTimer();
504+
});
509505

510-
if (!controller.value.isInitialized) {
511-
controller.initialize().then((_) {
512-
controller.play();
513-
});
514-
} else {
515-
if (isFinished) {
516-
controller.seekTo(Duration.zero);
517-
}
506+
_hideTimer?.cancel();
507+
controller.pause();
508+
} else {
509+
_cancelAndRestartTimer();
510+
511+
if (!controller.value.isInitialized) {
512+
controller.initialize().then((_) {
518513
controller.play();
519-
}
514+
});
515+
} else {
516+
controller.play();
520517
}
521-
});
518+
}
522519
}
523520

524521
void _startHideTimer() {

0 commit comments

Comments
 (0)