diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 4fdf02241f..f5e26cc430 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -583,8 +583,8 @@ class ManagerAPI { return showDialog( barrierDismissible: false, context: context, - builder: (context) => WillPopScope( - onWillPop: () async => false, + builder: (context) => PopScope( + canPop: 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 d1626ed5ab..45d2051943 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -15,7 +15,8 @@ class InstallerView extends StatelessWidget { return ViewModelBuilder.reactive( onViewModelReady: (model) => model.initialize(context), viewModelBuilder: () => InstallerViewModel(), - builder: (context, model, child) => WillPopScope( + builder: (context, model, child) => PopScope( + onPopInvoked: (bool didPop) => model.onPopInvoked(context, didPop), child: SafeArea( top: false, bottom: model.isPatching, @@ -83,7 +84,7 @@ class InstallerView extends StatelessWidget { maxLines: 1, overflow: TextOverflow.ellipsis, ), - onBackButtonPressed: () => model.onWillPop(context), + onBackButtonPressed: () => model.onBackButtonInvoked(context), bottom: PreferredSize( preferredSize: const Size(double.infinity, 1.0), child: GradientProgressIndicator(progress: model.progress), @@ -111,7 +112,6 @@ 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 39a59db4f8..c8f7e8cd0e 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -182,7 +182,8 @@ class InstallerViewModel extends BaseViewModel { Future copyLogs() async { final info = await AboutInfo.getInfo(); dynamic getValue(String patchName, Option option) { - final Option? savedOption = _managerAPI.getPatchOption(_app.packageName, patchName, option.key); + final Option? savedOption = + _managerAPI.getPatchOption(_app.packageName, patchName, option.key); if (savedOption != null) { return savedOption.value; } else { @@ -203,7 +204,6 @@ class InstallerViewModel extends BaseViewModel { 'App: ${_app.packageName} v${_app.version}', 'Patches version: ${_managerAPI.patchesVersion}', 'Patches: ${_patches.map((p) => p.name + (p.options.isEmpty ? '' : ' [${p.options.map((o) => '${o.title}: ${getValue(p.name, o)}').join(", ")}]')).toList().join(", ")}', - '\n- Settings', 'Allow changing patch selection: ${_managerAPI.isPatchesChangeEnabled()}', 'Version compatibility check: ${_managerAPI.isVersionCompatibilityCheckEnabled()}', @@ -427,25 +427,38 @@ class InstallerViewModel extends BaseViewModel { } } - Future onWillPop(BuildContext context) async { - if (isPatching) { + 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) { if (!cancel) { - cancel = true; - _toast.showBottom('installerView.pressBackAgain'); - } else if (!isCanceled) { - await stopPatcher(); + cleanPatcher(); } else { - _toast.showBottom('installerView.noExit'); + _patcherAPI.cleanPatcher(); } - return false; - } - if (!cancel) { - cleanPatcher(); + screenshotCallback.dispose(); + Navigator.of(context).pop(); } else { - _patcherAPI.cleanPatcher(); + if (isPatching) { + if (!cancel) { + cancel = true; + _toast.showBottom('installerView.pressBackAgain'); + } else if (!isCanceled) { + await stopPatcher(); + } else { + _toast.showBottom('installerView.noExit'); + } + } } - 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 13a4457e22..56c24d1718 100644 --- a/lib/ui/views/navigation/navigation_view.dart +++ b/lib/ui/views/navigation/navigation_view.dart @@ -13,13 +13,11 @@ class NavigationView extends StatelessWidget { return ViewModelBuilder.reactive( onViewModelReady: (model) => model.initialize(context), viewModelBuilder: () => locator(), - builder: (context, model, child) => WillPopScope( - onWillPop: () async { - if (model.currentIndex == 0) { - return true; - } else { + builder: (context, model, child) => PopScope( + canPop: model.currentIndex == 0, + onPopInvoked: (bool didPop) { + if (!didPop) { model.setIndex(0); - return false; } }, child: Scaffold(