Bladeren bron

[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)
Ashil 1 jaar geleden
bovenliggende
commit
dac0ddf41c

+ 3 - 3
mobile/lib/ui/account/recovery_page.dart

@@ -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,
                     ),
                   );

+ 2 - 2
mobile/lib/ui/common/linear_progress_dialog.dart

@@ -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,

+ 2 - 2
mobile/lib/ui/common/progress_dialog.dart

@@ -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,

+ 9 - 2
mobile/lib/ui/payment/payment_web_page.dart

@@ -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),

+ 2 - 2
mobile/lib/ui/settings/app_update_dialog.dart

@@ -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(

+ 17 - 19
mobile/lib/ui/tabs/home_widget.dart

@@ -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;
-          }
-        },
       ),
     );
   }

+ 2 - 2
mobile/lib/ui/tools/app_lock.dart

@@ -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),
     );
   }
 

+ 3 - 3
mobile/lib/ui/tools/editor/image_editor_page.dart

@@ -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(