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,42 +299,46 @@ 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 Backdrop(
|
child: new WillPopScope(
|
||||||
backTitle: const Text('Options'),
|
onWillPop: () {
|
||||||
backLayer: widget.optionsPage,
|
// Pop the category page if Android back button is pressed.
|
||||||
frontAction: new AnimatedSwitcher(
|
if (_category != null) {
|
||||||
duration: _kFrontLayerSwitchDuration,
|
setState(() => _category = null);
|
||||||
child: _category == null
|
return new Future<bool>.value(false);
|
||||||
? const _FlutterLogo()
|
}
|
||||||
: new IconButton(
|
return new Future<bool>.value(true);
|
||||||
icon: const BackButtonIcon(),
|
},
|
||||||
tooltip: 'Back',
|
child: new Backdrop(
|
||||||
onPressed: () {
|
backTitle: const Text('Options'),
|
||||||
setState(() {
|
backLayer: widget.optionsPage,
|
||||||
_category = null;
|
frontAction: new AnimatedSwitcher(
|
||||||
});
|
duration: _kFrontLayerSwitchDuration,
|
||||||
},
|
child: _category == null
|
||||||
),
|
? const _FlutterLogo()
|
||||||
),
|
: new IconButton(
|
||||||
frontTitle: new AnimatedSwitcher(
|
icon: const BackButtonIcon(),
|
||||||
duration: _kFrontLayerSwitchDuration,
|
tooltip: 'Back',
|
||||||
child: _category == null
|
onPressed: () => setState(() => _category = null),
|
||||||
? const Text('Flutter gallery')
|
),
|
||||||
: new Text(_category.name),
|
),
|
||||||
),
|
frontTitle: new AnimatedSwitcher(
|
||||||
frontHeading: new Container(height: 24.0),
|
duration: _kFrontLayerSwitchDuration,
|
||||||
frontLayer: new AnimatedSwitcher(
|
child: _category == null
|
||||||
duration: _kFrontLayerSwitchDuration,
|
? const Text('Flutter gallery')
|
||||||
child: _category != null
|
: new Text(_category.name),
|
||||||
? new _DemosPage(_category)
|
),
|
||||||
: new _CategoriesPage(
|
frontHeading: new Container(height: 24.0),
|
||||||
categories: kAllGalleryDemoCategories,
|
frontLayer: new AnimatedSwitcher(
|
||||||
onCategoryTap: (GalleryDemoCategory category) {
|
duration: _kFrontLayerSwitchDuration,
|
||||||
setState(() {
|
child: _category != null
|
||||||
_category = category;
|
? new _DemosPage(_category)
|
||||||
});
|
: new _CategoriesPage(
|
||||||
},
|
categories: kAllGalleryDemoCategories,
|
||||||
),
|
onCategoryTap: (GalleryDemoCategory category) {
|
||||||
|
setState(() => _category = category);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user