fullscreen: leave when last entry is deleted

This commit is contained in:
Thibault Deckers 2020-10-29 14:55:01 +09:00
parent bb23e7a939
commit f1a26d14ab
2 changed files with 13 additions and 8 deletions

View file

@ -179,7 +179,7 @@ class ImageSearchDelegate {
void _goBack(BuildContext context) { void _goBack(BuildContext context) {
_clean(); _clean();
Navigator.of(context).pop(); Navigator.pop(context);
} }
void _goToCollectionPage(BuildContext context, CollectionFilter filter) { void _goToCollectionPage(BuildContext context, CollectionFilter filter) {

View file

@ -314,7 +314,7 @@ class FullscreenBodyState extends State<FullscreenBody> with SingleTickerProvide
void _updateEntry() { void _updateEntry() {
if (_currentHorizontalPage != null && entries.isNotEmpty && _currentHorizontalPage >= entries.length) { if (_currentHorizontalPage != null && entries.isNotEmpty && _currentHorizontalPage >= entries.length) {
// as of Flutter v1.20.2, `PageView` does not call `onPageChanged` when the last page is deleted // as of Flutter v1.22.2, `PageView` does not call `onPageChanged` when the last page is deleted
// so we manually track the page change, and let the entry update follow // so we manually track the page change, and let the entry update follow
_onHorizontalPageChanged(entries.length - 1); _onHorizontalPageChanged(entries.length - 1);
return; return;
@ -462,7 +462,7 @@ class _FullscreenVerticalPageViewState extends State<FullscreenVerticalPageView>
void _registerWidget(FullscreenVerticalPageView widget) { void _registerWidget(FullscreenVerticalPageView widget) {
widget.verticalPager.addListener(_onVerticalPageControllerChanged); widget.verticalPager.addListener(_onVerticalPageControllerChanged);
widget.entryNotifier.addListener(_onEntryChanged); widget.entryNotifier.addListener(_onEntryChanged);
_onEntryChanged(); if (_oldEntry != entry) _onEntryChanged();
} }
void _unregisterWidget(FullscreenVerticalPageView widget) { void _unregisterWidget(FullscreenVerticalPageView widget) {
@ -529,12 +529,17 @@ class _FullscreenVerticalPageViewState extends State<FullscreenVerticalPageView>
// when the entry changed (e.g. by scrolling through the PageView, or if the entry got deleted) // when the entry changed (e.g. by scrolling through the PageView, or if the entry got deleted)
void _onEntryChanged() { void _onEntryChanged() {
_oldEntry?.imageChangeNotifier?.removeListener(_onImageChanged); _oldEntry?.imageChangeNotifier?.removeListener(_onImageChanged);
entry?.imageChangeNotifier?.addListener(_onImageChanged);
_oldEntry = entry; _oldEntry = entry;
// make sure to locate the entry,
// so that we can display the address instead of coordinates if (entry != null) {
// even when background locating has not reached this entry yet entry.imageChangeNotifier.addListener(_onImageChanged);
entry?.locate(); // make sure to locate the entry,
// so that we can display the address instead of coordinates
// even when background locating has not reached this entry yet
entry.locate();
} else {
Navigator.pop(context);
}
} }
// when the entry image itself changed (e.g. after rotation) // when the entry image itself changed (e.g. after rotation)