From 1c32b055f02a23f856afd69e2c64d6eaa05e7643 Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Thu, 15 Feb 2024 08:00:03 +0000 Subject: [PATCH] Revert "refactor: Replace deprecated `WillPopScope` (#1604)" This reverts commit ef9b1d5c2d72c6787246c4b6d11929044a13b54d. Why is this so hard to implement??? Are we missing something?? --- lib/services/manager_api.dart | 4 ++-- lib/ui/views/installer/installer_view.dart | 10 +++++++--- lib/ui/views/navigation/navigation_view.dart | 12 ++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 091ddf2256..5257dddf8e 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -619,8 +619,8 @@ class ManagerAPI { return showDialog( barrierDismissible: false, context: context, - builder: (context) => PopScope( - canPop: false, + builder: (context) => WillPopScope( + onWillPop: () async => false, child: AlertDialog( title: Text(t.warning), content: ValueListenableBuilder( diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index 49fe9b9df0..2ff230b39e 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -16,9 +16,12 @@ class InstallerView extends StatelessWidget { return ViewModelBuilder.reactive( onViewModelReady: (model) => model.initialize(context), viewModelBuilder: () => InstallerViewModel(), - builder: (context, model, child) => PopScope( - onPopInvoked: (bool didPop) => model.onWillPop(context), - canPop: false, + builder: (context, model, child) => WillPopScope( + /* + TODO(any): migrate to [PopScope], + we've tried to migrate it two times but + reverted it because we couldn't exit out of the screen. + */ child: SafeArea( top: false, bottom: model.isPatching, @@ -108,6 +111,7 @@ class InstallerView extends StatelessWidget { ), ), ), + onWillPop: () => model.onWillPop(context), ), ); } diff --git a/lib/ui/views/navigation/navigation_view.dart b/lib/ui/views/navigation/navigation_view.dart index 285331fc8f..65a41ca375 100644 --- a/lib/ui/views/navigation/navigation_view.dart +++ b/lib/ui/views/navigation/navigation_view.dart @@ -13,10 +13,14 @@ class NavigationView extends StatelessWidget { return ViewModelBuilder.reactive( onViewModelReady: (model) => model.initialize(context), viewModelBuilder: () => locator(), - builder: (context, model, child) => PopScope( - canPop: model.currentIndex == 0, - onPopInvoked: (bool didPop) => { - if (!didPop) model.setIndex(0), + builder: (context, model, child) => WillPopScope( + onWillPop: () async { + if (model.currentIndex == 0) { + return true; + } else { + model.setIndex(0); + return false; + } }, child: Scaffold( body: PageTransitionSwitcher(