[mob][photos] Migrate use of WillPopScope to PopScope (#1473)

## Description

[Documentation followed for the
migration](https://docs.flutter.dev/release/breaking-changes/android-predictive-back)

## Tests

- [x] Tested screens in which migration wasn't straight forward
(HomeScreen)
This commit is contained in:
Ashil 2024-04-19 09:16:42 +05:30 committed by GitHub
parent d430616ccb
commit dac0ddf41c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 40 additions and 35 deletions

View file

@ -59,9 +59,9 @@ class _RecoveryPageState extends State<RecoveryPage> {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: const PasswordEntryPage(
return const PopScope(
canPop: false,
child: PasswordEntryPage(
mode: PasswordEntryMode.reset,
),
);

View file

@ -27,8 +27,8 @@ class LinearProgressDialogState extends State<LinearProgressDialog> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
return PopScope(
canPop: false,
child: AlertDialog(
title: Text(
widget.message,

View file

@ -155,8 +155,8 @@ class ProgressDialog {
barrierColor: _barrierColor,
builder: (BuildContext context) {
_dismissingContext = context;
return WillPopScope(
onWillPop: () async => _barrierDismissible,
return PopScope(
canPop: _barrierDismissible,
child: Dialog(
backgroundColor: _backgroundColor,
insetAnimationCurve: _insetAnimCurve,

View file

@ -52,8 +52,15 @@ class _PaymentWebPageState extends State<PaymentWebPage> {
if (initPaymentUrl == null) {
return const EnteLoadingWidget();
}
return WillPopScope(
onWillPop: (() async => _buildPageExitWidget(context)),
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
if (didPop) return;
final shouldPop = await _buildPageExitWidget(context);
if (shouldPop) {
Navigator.of(context).pop();
}
},
child: Scaffold(
appBar: AppBar(
title: Text(S.of(context).subscription),

View file

@ -83,8 +83,8 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
);
final shouldForceUpdate =
UpdateService.instance.shouldForceUpdate(widget.latestVersionInfo!);
return WillPopScope(
onWillPop: () async => !shouldForceUpdate,
return PopScope(
canPop: !shouldForceUpdate,
child: AlertDialog(
key: const ValueKey("updateAppDialog"),
title: Column(

View file

@ -315,7 +315,23 @@ class _HomeWidgetState extends State<HomeWidget> {
final enableDrawer = LocalSyncService.instance.hasCompletedFirstImport();
final action = AppLifecycleService.instance.mediaExtensionAction.action;
return UserDetailsStateWidget(
child: WillPopScope(
child: PopScope(
canPop: false,
onPopInvoked: (didPop) async {
if (didPop) return;
if (_selectedTabIndex == 0) {
if (isSettingsOpen) {
Navigator.pop(context);
} else if (Platform.isAndroid && action == IntentAction.main) {
unawaited(MoveToBackground.moveTaskToBack());
} else {
Navigator.pop(context);
}
} else {
Bus.instance
.fire(TabChangedEvent(0, TabChangedEventSource.backButton));
}
},
child: Scaffold(
drawerScrimColor: getEnteColorScheme(context).strokeFainter,
drawerEnableOpenDragGesture: false,
@ -341,24 +357,6 @@ class _HomeWidgetState extends State<HomeWidget> {
),
resizeToAvoidBottomInset: false,
),
onWillPop: () async {
if (_selectedTabIndex == 0) {
if (isSettingsOpen) {
Navigator.pop(context);
return false;
}
if (Platform.isAndroid && action == IntentAction.main) {
unawaited(MoveToBackground.moveTaskToBack());
return false;
} else {
return true;
}
} else {
Bus.instance
.fire(TabChangedEvent(0, TabChangedEventSource.backButton));
return false;
}
},
),
);
}

View file

@ -137,9 +137,9 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
}
Widget get _lockScreen {
return WillPopScope(
return PopScope(
canPop: false,
child: this.widget.lockScreen,
onWillPop: () => Future.value(false),
);
}

View file

@ -63,14 +63,14 @@ class _ImageEditorPageState extends State<ImageEditorPage> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
if (_hasBeenEdited()) {
await _showExitConfirmationDialog(context);
} else {
replacePage(context, DetailPage(widget.detailPageConfig));
}
return false;
},
child: Scaffold(
appBar: AppBar(