Breaking google testing 
revert of: https://github.com/flutter/flutter/pull/120385
b/295065534
This commit is contained in:
Jesús S Guerrero
2023-08-08 16:16:52 -07:00
committed by GitHub
parent b77b149df6
commit 2728ba0f23
36 changed files with 303 additions and 3227 deletions

View File

@@ -48,9 +48,9 @@ class CupertinoNavigationDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopScope(
return WillPopScope(
// Prevent swipe popping of this page. Use explicit exit buttons only.
canPop: false,
onWillPop: () => Future<bool>.value(true),
child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: CupertinoTabScaffold(

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
// This demo is based on
@@ -110,15 +109,16 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
bool _hasName = false;
late String _eventName;
Future<void> _handlePopInvoked(bool didPop) async {
if (didPop) {
return;
Future<bool> _onWillPop() async {
_saveNeeded = _hasLocation || _hasName || _saveNeeded;
if (!_saveNeeded) {
return true;
}
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle = theme.textTheme.titleMedium!.copyWith(color: theme.textTheme.bodySmall!.color);
final bool? shouldDiscard = await showDialog<bool>(
return showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
@@ -130,31 +130,19 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
TextButton(
child: const Text('CANCEL'),
onPressed: () {
// Pop the confirmation dialog and indicate that the page should
// not be popped.
Navigator.of(context).pop(false);
Navigator.of(context).pop(false); // Pops the confirmation dialog but not the page.
},
),
TextButton(
child: const Text('DISCARD'),
onPressed: () {
// Pop the confirmation dialog and indicate that the page should
// be popped, too.
Navigator.of(context).pop(true);
Navigator.of(context).pop(true); // Returning true to _onWillPop will pop again.
},
),
],
);
},
);
if (shouldDiscard ?? false) {
// Since this is the root route, quit the app where possible by invoking
// the SystemNavigator. If this wasn't the root route, then
// Navigator.maybePop could be used instead.
// See https://github.com/flutter/flutter/issues/11490
SystemNavigator.pop();
}
) as Future<bool>;
}
@override
@@ -174,8 +162,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
],
),
body: Form(
canPop: !_saveNeeded && !_hasLocation && !_hasName,
onPopInvoked: _handlePopInvoked,
onWillPop: _onWillPop,
child: Scrollbar(
child: ListView(
primary: true,

View File

@@ -143,9 +143,10 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
return null;
}
Future<void> _handlePopInvoked(bool didPop) async {
if (didPop) {
return;
Future<bool> _warnUserAboutInvalidData() async {
final FormState? form = _formKey.currentState;
if (form == null || !_formWasEdited || form.validate()) {
return true;
}
final bool? result = await showDialog<bool>(
@@ -167,14 +168,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
);
},
);
if (result ?? false) {
// Since this is the root route, quit the app where possible by invoking
// the SystemNavigator. If this wasn't the root route, then
// Navigator.maybePop could be used instead.
// See https://github.com/flutter/flutter/issues/11490
SystemNavigator.pop();
}
return result!;
}
@override
@@ -191,8 +185,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
child: Form(
key: _formKey,
autovalidateMode: _autovalidateMode,
canPop: _formKey.currentState == null || !_formWasEdited || _formKey.currentState!.validate(),
onPopInvoked: _handlePopInvoked,
onWillPop: _warnUserAboutInvalidData,
child: Scrollbar(
child: SingleChildScrollView(
primary: true,

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:scoped_model/scoped_model.dart';
import 'colors.dart';
@@ -360,12 +361,14 @@ class ExpandingBottomSheetState extends State<ExpandingBottomSheet> with TickerP
// Closes the cart if the cart is open, otherwise exits the app (this should
// only be relevant for Android).
void _handlePopInvoked(bool didPop) {
if (didPop) {
return;
Future<bool> _onWillPop() async {
if (!_isOpen) {
await SystemNavigator.pop();
return true;
}
close();
return true;
}
@override
@@ -375,9 +378,8 @@ class ExpandingBottomSheetState extends State<ExpandingBottomSheet> with TickerP
duration: const Duration(milliseconds: 225),
curve: Curves.easeInOut,
alignment: FractionalOffset.topLeft,
child: PopScope(
canPop: !_isOpen,
onPopInvoked: _handlePopInvoked,
child: WillPopScope(
onWillPop: _onWillPop,
child: AnimatedBuilder(
animation: widget.hideController,
builder: _buildSlideAnimation,

View File

@@ -325,14 +325,14 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
backgroundColor: isDark ? _kFlutterBlue : theme.primaryColor,
body: SafeArea(
bottom: false,
child: PopScope(
canPop: _category == null,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}
child: WillPopScope(
onWillPop: () {
// Pop the category page if Android back button is pressed.
setState(() => _category = null);
if (_category != null) {
setState(() => _category = null);
return Future<bool>.value(false);
}
return Future<bool>.value(true);
},
child: Backdrop(
backTitle: const Text('Options'),