screensaver: fixed autopilot when device orientation changes

This commit is contained in:
Thibault Deckers 2022-08-29 10:04:20 +02:00
parent bf88e2d816
commit 36d92aaf38
2 changed files with 23 additions and 10 deletions

View file

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## <a id="unreleased"></a>[Unreleased] ## <a id="unreleased"></a>[Unreleased]
### Fixed
- screensaver stopping when device orientation changes
## <a id="v1.6.12"></a>[v1.6.12] - 2022-08-27 ## <a id="v1.6.12"></a>[v1.6.12] - 2022-08-27
### Added ### Added

View file

@ -29,7 +29,7 @@ class ScreenSaverPage extends StatefulWidget {
State<ScreenSaverPage> createState() => _ScreenSaverPageState(); State<ScreenSaverPage> createState() => _ScreenSaverPageState();
} }
class _ScreenSaverPageState extends State<ScreenSaverPage> { class _ScreenSaverPageState extends State<ScreenSaverPage> with WidgetsBindingObserver {
late final ViewerController _viewerController; late final ViewerController _viewerController;
CollectionLens? _slideshowCollection; CollectionLens? _slideshowCollection;
@ -47,24 +47,24 @@ class _ScreenSaverPageState extends State<ScreenSaverPage> {
); );
source.stateNotifier.addListener(_onSourceStateChanged); source.stateNotifier.addListener(_onSourceStateChanged);
_initSlideshowCollection(); _initSlideshowCollection();
} WidgetsBinding.instance.addObserver(this);
void _onSourceStateChanged() {
if (_slideshowCollection == null) {
_initSlideshowCollection();
if (_slideshowCollection != null) {
setState(() {});
}
}
} }
@override @override
void dispose() { void dispose() {
source.stateNotifier.removeListener(_onSourceStateChanged); source.stateNotifier.removeListener(_onSourceStateChanged);
_viewerController.dispose(); _viewerController.dispose();
WidgetsBinding.instance.removeObserver(this);
super.dispose(); super.dispose();
} }
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_viewerController.autopilot = true;
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget child; Widget child;
@ -102,6 +102,15 @@ class _ScreenSaverPageState extends State<ScreenSaverPage> {
); );
} }
void _onSourceStateChanged() {
if (_slideshowCollection == null) {
_initSlideshowCollection();
if (_slideshowCollection != null) {
setState(() {});
}
}
}
void _initSlideshowCollection() { void _initSlideshowCollection() {
if (source.stateNotifier.value != SourceState.ready || _slideshowCollection != null) return; if (source.stateNotifier.value != SourceState.ready || _slideshowCollection != null) return;