Skip to content

Commit 7c1009f

Browse files
authored
Merge pull request #194 from Piwigo/feature/back_button_not_working
Resolve #193 "pop scope not working"
2 parents 919ac62 + 0b6e3ef commit 7c1009f

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

lib/views/album/album_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,20 @@ class _AlbumPageState extends State<AlbumPage> {
198198
}
199199

200200
void _onWillPop(bool pop) {
201+
if (pop) return;
201202
if (_selectedList.isNotEmpty) {
202203
setState(() {
203204
_selectedList.clear();
204205
});
206+
} else {
207+
Navigator.of(context).pop();
205208
}
206209
}
207210

208211
@override
209212
Widget build(BuildContext context) {
210213
return PopScope(
211-
canPop: _selectedList.isEmpty,
214+
canPop: false,
212215
onPopInvoked: _onWillPop,
213216
child: Scaffold(
214217
body: SafeArea(

lib/views/image/image_favorites_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ class _ImageFavoritesPageState extends State<ImageFavoritesPage> {
6161
bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty;
6262

6363
void _onWillPop(bool pop) async {
64+
if (pop) return;
6465
if (_selectedList.isNotEmpty) {
6566
setState(() {
6667
_selectedList.clear();
6768
});
69+
} else {
70+
Navigator.of(context).pop();
6871
}
6972
}
7073

@@ -141,7 +144,7 @@ class _ImageFavoritesPageState extends State<ImageFavoritesPage> {
141144
@override
142145
Widget build(BuildContext context) {
143146
return PopScope(
144-
canPop: _selectedList.isEmpty,
147+
canPop: false,
145148
onPopInvoked: _onWillPop,
146149
child: Scaffold(
147150
body: SafeArea(

lib/views/image/image_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class _ImagePageState extends State<ImagePage> {
178178
/// * If overlay is hidden, show it.
179179
/// * Otherwise, close the page.
180180
void _onWillPop(bool pop) {
181+
if (pop) return;
181182
if (!_showOverlay) {
182183
setState(() {
183184
_showOverlay = true;
@@ -282,7 +283,7 @@ class _ImagePageState extends State<ImagePage> {
282283
@override
283284
Widget build(BuildContext context) {
284285
return PopScope(
285-
canPop: !_showOverlay,
286+
canPop: false,
286287
onPopInvoked: _onWillPop,
287288
child: Scaffold(
288289
backgroundColor: Colors.black,

lib/views/image/image_search_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ class _ImageSearchPageState extends State<ImageSearchPage> {
6464
bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty;
6565

6666
void _onWillPop(bool pop) {
67+
if (pop) return;
6768
if (_selectedList.isNotEmpty) {
6869
setState(() {
6970
_selectedList.clear();
7071
});
72+
} else {
73+
Navigator.of(context).pop();
7174
}
7275
}
7376

@@ -148,7 +151,7 @@ class _ImageSearchPageState extends State<ImageSearchPage> {
148151
@override
149152
Widget build(BuildContext context) {
150153
return PopScope(
151-
canPop: _selectedList.isEmpty,
154+
canPop: false,
152155
onPopInvoked: _onWillPop,
153156
child: Scaffold(
154157
body: SafeArea(

lib/views/image/image_tags_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ class _ImageTagsPageState extends State<ImageTagsPage> {
6363
bool get _hasNonFavorites => _selectedList.where((image) => !image.favorite).isNotEmpty;
6464

6565
void _onWillPop(bool pop) {
66+
if (pop) return null;
6667
if (_selectedList.isNotEmpty) {
6768
setState(() {
6869
_selectedList.clear();
6970
});
71+
} else {
72+
Navigator.of(context).pop();
7073
}
7174
}
7275

@@ -143,7 +146,7 @@ class _ImageTagsPageState extends State<ImageTagsPage> {
143146
@override
144147
Widget build(BuildContext context) {
145148
return PopScope(
146-
canPop: _selectedList.isEmpty,
149+
canPop: false,
147150
onPopInvoked: _onWillPop,
148151
child: Scaffold(
149152
body: SafeArea(

0 commit comments

Comments
 (0)