diff --git a/lib/widget/video_viewer.dart b/lib/widget/video_viewer.dart index 5e53756b..8c744ceb 100644 --- a/lib/widget/video_viewer.dart +++ b/lib/widget/video_viewer.dart @@ -13,8 +13,9 @@ import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/request_public_link.dart'; import 'package:nc_photos/widget/animated_visibility.dart'; +import 'package:nc_photos/widget/disposable.dart'; +import 'package:nc_photos/widget/wakelock_util.dart'; import 'package:video_player/video_player.dart'; -import 'package:wakelock/wakelock.dart'; class VideoViewer extends StatefulWidget { VideoViewer({ @@ -41,7 +42,8 @@ class VideoViewer extends StatefulWidget { final bool canPlay; } -class _VideoViewerState extends State { +class _VideoViewerState extends State + with DisposableManagerMixin { @override initState() { super.initState(); @@ -56,8 +58,14 @@ class _VideoViewerState extends State { duration: k.snackBarDurationNormal, )); }); + } - Wakelock.enable(); + @override + initDisposables() { + return [ + ...super.initDisposables(), + WakelockControllerDisposable(), + ]; } @override @@ -81,7 +89,6 @@ class _VideoViewerState extends State { dispose() { super.dispose(); _controller.dispose(); - Wakelock.disable(); } void _initController(String url) async { diff --git a/lib/widget/wakelock_util.dart b/lib/widget/wakelock_util.dart new file mode 100644 index 00000000..b5497fde --- /dev/null +++ b/lib/widget/wakelock_util.dart @@ -0,0 +1,15 @@ +import 'package:flutter/widgets.dart'; +import 'package:nc_photos/widget/disposable.dart'; +import 'package:wakelock/wakelock.dart'; + +class WakelockControllerDisposable implements Disposable { + @override + init(State state) { + Wakelock.enable(); + } + + @override + dispose(State state) { + Wakelock.disable(); + } +}