From 635b2a7821b3a4f6bfc5160f62285e8b29ad24e6 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 23 Mar 2022 19:55:01 -0400 Subject: [PATCH] Use pop instead of exit for sleep timer (#84) Apple probably won't approve of exiting the app programmatically based on their guidelines, so going ahead with pop like other apps. --- lib/screens/channel/stores/video_store.dart | 6 +++--- lib/screens/channel/video/video_overlay.dart | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/screens/channel/stores/video_store.dart b/lib/screens/channel/stores/video_store.dart index a861bdd6..46f65f09 100644 --- a/lib/screens/channel/stores/video_store.dart +++ b/lib/screens/channel/stores/video_store.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -164,7 +163,8 @@ abstract class _VideoStoreBase with Store { } /// Updates the sleep timer with [sleepHours] and [sleepMinutes]. - void updateSleepTimer() { + /// Calls [onTimerFinished] when the sleep timer completes. + void updateSleepTimer({required void Function() onTimerFinished}) { // If hours and minutes are 0, do nothing. if (sleepHours == 0 && sleepMinutes == 0) return; @@ -185,7 +185,7 @@ abstract class _VideoStoreBase with Store { // If the timer is up, cancel the timer and exit the app. if (timeRemaining.inSeconds == 0) { timer.cancel(); - Platform.isIOS ? exit(0) : SystemNavigator.pop(); + onTimerFinished(); return; } diff --git a/lib/screens/channel/video/video_overlay.dart b/lib/screens/channel/video/video_overlay.dart index 98c99d89..a62b2995 100644 --- a/lib/screens/channel/video/video_overlay.dart +++ b/lib/screens/channel/video/video_overlay.dart @@ -18,7 +18,7 @@ class VideoOverlay extends StatefulWidget { } class _VideoOverlayState extends State { - Future _showSleepTimerDialog(BuildContext context) { + Future _showSleepTimerDialog(BuildContext oldContext) { return showDialog( context: context, builder: (context) => AlertDialog( @@ -69,11 +69,18 @@ class _VideoOverlayState extends State { actions: [ TextButton( onPressed: Navigator.of(context).pop, - child: const Text('Close'), + child: const Text('Dismiss'), ), Observer( builder: (context) => TextButton( - onPressed: widget.videoStore.sleepHours == 0 && widget.videoStore.sleepMinutes == 0 ? null : widget.videoStore.updateSleepTimer, + onPressed: widget.videoStore.sleepHours == 0 && widget.videoStore.sleepMinutes == 0 + ? null + : () => widget.videoStore.updateSleepTimer( + onTimerFinished: () => Navigator.popUntil( + oldContext, + (route) => route.isFirst, + ), + ), child: const Text('Set Timer'), style: TextButton.styleFrom(primary: Colors.green), ), @@ -140,7 +147,10 @@ class _VideoOverlayState extends State { final sleepTimerButton = IconButton( tooltip: 'Sleep Timer', - icon: const Icon(Icons.timer), + icon: const Icon( + Icons.timer, + color: Colors.white, + ), onPressed: () => _showSleepTimerDialog(context), );