소스 검색

disable wakeLock on dispose if not enabled from settings

ashilkn 2 년 전
부모
커밋
730450835f
1개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      lib/ui/viewer/file/detail_page.dart

+ 8 - 1
lib/ui/viewer/file/detail_page.dart

@@ -75,9 +75,12 @@ class _DetailPageState extends State<DetailPage> {
   bool _shouldHideAppBar = false;
   GlobalKey<FadingAppBarState> _appBarKey;
   GlobalKey<FadingBottomBarState> _bottomBarKey;
+  bool wakeLockEnabledHere;
 
   @override
   void initState() {
+    wakeLockEnabledHere = false;
+
     _files = [
       ...widget.config.files
     ]; // Make a copy since we append preceding and succeeding entries to this
@@ -92,6 +95,11 @@ class _DetailPageState extends State<DetailPage> {
       SystemUiMode.manual,
       overlays: SystemUiOverlay.values,
     );
+    if (wakeLockEnabledHere) {
+      Wakelock.enabled.then((isEnabled) {
+        isEnabled ? Wakelock.disable() : null;
+      });
+    }
     super.dispose();
   }
 
@@ -254,7 +262,6 @@ class _DetailPageState extends State<DetailPage> {
   }
 
   void _keepScreenAliveOnPlaying(bool isPlaying) {
-    bool wakeLockEnabledHere = false;
     if (isPlaying) {
       Wakelock.enabled.then((value) {
         if (value == false) {