Unverified Commit b2db3baf authored by xster's avatar xster Committed by GitHub

Make Android back button presses in a demo category not unexpectedly quit the app (#17224)

parent 22c12f9f
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:developer';
import 'dart:math' as math;
......@@ -298,6 +299,15 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
backgroundColor: isDark ? _kFlutterBlue : theme.primaryColor,
body: new SafeArea(
bottom: false,
child: new WillPopScope(
onWillPop: () {
// Pop the category page if Android back button is pressed.
if (_category != null) {
setState(() => _category = null);
return new Future<bool>.value(false);
}
return new Future<bool>.value(true);
},
child: new Backdrop(
backTitle: const Text('Options'),
backLayer: widget.optionsPage,
......@@ -308,11 +318,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
: new IconButton(
icon: const BackButtonIcon(),
tooltip: 'Back',
onPressed: () {
setState(() {
_category = null;
});
},
onPressed: () => setState(() => _category = null),
),
),
frontTitle: new AnimatedSwitcher(
......@@ -329,14 +335,13 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
: new _CategoriesPage(
categories: kAllGalleryDemoCategories,
onCategoryTap: (GalleryDemoCategory category) {
setState(() {
_category = category;
});
setState(() => _category = category);
},
),
),
),
),
),
);
assert(() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment