diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 85306873..7a9e091d 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -582,8 +582,8 @@ class ManagerAPI { return showDialog( barrierDismissible: false, context: context, - builder: (context) => PopScope( - canPop: false, + builder: (context) => WillPopScope( + onWillPop: () async => false, child: AlertDialog( backgroundColor: Theme.of(context).colorScheme.secondaryContainer, title: I18nText('warning'), diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index 45d20519..d1626ed5 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -15,8 +15,7 @@ class InstallerView extends StatelessWidget { return ViewModelBuilder.reactive( onViewModelReady: (model) => model.initialize(context), viewModelBuilder: () => InstallerViewModel(), - builder: (context, model, child) => PopScope( - onPopInvoked: (bool didPop) => model.onPopInvoked(context, didPop), + builder: (context, model, child) => WillPopScope( child: SafeArea( top: false, bottom: model.isPatching, @@ -84,7 +83,7 @@ class InstallerView extends StatelessWidget { maxLines: 1, overflow: TextOverflow.ellipsis, ), - onBackButtonPressed: () => model.onBackButtonInvoked(context), + onBackButtonPressed: () => model.onWillPop(context), bottom: PreferredSize( preferredSize: const Size(double.infinity, 1.0), child: GradientProgressIndicator(progress: model.progress), @@ -112,6 +111,7 @@ class InstallerView extends StatelessWidget { ), ), ), + onWillPop: () => model.onWillPop(context), ), ); } diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 02691bb3..d16f1309 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -489,38 +489,25 @@ class InstallerViewModel extends BaseViewModel { } } - bool canPop() { - return !isPatching; - } - - void onBackButtonInvoked(BuildContext context) { - if (canPop()) { - onPopInvoked(context, true); - } else { - onPopInvoked(context, false); - } - } - - Future onPopInvoked(BuildContext context, bool didPop) async { - if (didPop) { + Future onWillPop(BuildContext context) async { + if (isPatching) { if (!cancel) { - cleanPatcher(); + cancel = true; + _toast.showBottom('installerView.pressBackAgain'); + } else if (!isCanceled) { + await stopPatcher(); } else { - _patcherAPI.cleanPatcher(); - } - screenshotCallback.dispose(); - Navigator.of(context).pop(); - } else { - if (isPatching) { - if (!cancel) { - cancel = true; - _toast.showBottom('installerView.pressBackAgain'); - } else if (!isCanceled) { - await stopPatcher(); - } else { - _toast.showBottom('installerView.noExit'); - } + _toast.showBottom('installerView.noExit'); } + return false; } + if (!cancel) { + cleanPatcher(); + } else { + _patcherAPI.cleanPatcher(); + } + screenshotCallback.dispose(); + Navigator.of(context).pop(); + return true; } } diff --git a/lib/ui/views/navigation/navigation_view.dart b/lib/ui/views/navigation/navigation_view.dart index 56c24d17..13a4457e 100644 --- a/lib/ui/views/navigation/navigation_view.dart +++ b/lib/ui/views/navigation/navigation_view.dart @@ -13,11 +13,13 @@ 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) { + builder: (context, model, child) => WillPopScope( + onWillPop: () async { + if (model.currentIndex == 0) { + return true; + } else { model.setIndex(0); + return false; } }, child: Scaffold(