mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Make Android back button presses in a demo category not unexpectedly quit the app (#17224)
This commit is contained in:
parent
22c12f9f92
commit
b2db3bafef
@ -2,6 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
@ -298,6 +299,15 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
|
|||||||
backgroundColor: isDark ? _kFlutterBlue : theme.primaryColor,
|
backgroundColor: isDark ? _kFlutterBlue : theme.primaryColor,
|
||||||
body: new SafeArea(
|
body: new SafeArea(
|
||||||
bottom: false,
|
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(
|
child: new Backdrop(
|
||||||
backTitle: const Text('Options'),
|
backTitle: const Text('Options'),
|
||||||
backLayer: widget.optionsPage,
|
backLayer: widget.optionsPage,
|
||||||
@ -308,11 +318,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
|
|||||||
: new IconButton(
|
: new IconButton(
|
||||||
icon: const BackButtonIcon(),
|
icon: const BackButtonIcon(),
|
||||||
tooltip: 'Back',
|
tooltip: 'Back',
|
||||||
onPressed: () {
|
onPressed: () => setState(() => _category = null),
|
||||||
setState(() {
|
|
||||||
_category = null;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
frontTitle: new AnimatedSwitcher(
|
frontTitle: new AnimatedSwitcher(
|
||||||
@ -329,14 +335,13 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
|
|||||||
: new _CategoriesPage(
|
: new _CategoriesPage(
|
||||||
categories: kAllGalleryDemoCategories,
|
categories: kAllGalleryDemoCategories,
|
||||||
onCategoryTap: (GalleryDemoCategory category) {
|
onCategoryTap: (GalleryDemoCategory category) {
|
||||||
setState(() {
|
setState(() => _category = category);
|
||||||
_category = category;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(() {
|
assert(() {
|
||||||
|
Loading…
Reference in New Issue
Block a user