revert: "feat: improve predictive back (#1487)"

This reverts commit 06ff36c836.

Signed-off-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
validcube 2023-12-11 19:02:13 +07:00
parent 637641cf54
commit 7f26c5bd45
No known key found for this signature in database
GPG key ID: DBA94253E1D3F267
4 changed files with 27 additions and 38 deletions

View file

@ -582,8 +582,8 @@ class ManagerAPI {
return showDialog( return showDialog(
barrierDismissible: false, barrierDismissible: false,
context: context, context: context,
builder: (context) => PopScope( builder: (context) => WillPopScope(
canPop: false, onWillPop: () async => false,
child: AlertDialog( child: AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer, backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: I18nText('warning'), title: I18nText('warning'),

View file

@ -15,8 +15,7 @@ class InstallerView extends StatelessWidget {
return ViewModelBuilder<InstallerViewModel>.reactive( return ViewModelBuilder<InstallerViewModel>.reactive(
onViewModelReady: (model) => model.initialize(context), onViewModelReady: (model) => model.initialize(context),
viewModelBuilder: () => InstallerViewModel(), viewModelBuilder: () => InstallerViewModel(),
builder: (context, model, child) => PopScope( builder: (context, model, child) => WillPopScope(
onPopInvoked: (bool didPop) => model.onPopInvoked(context, didPop),
child: SafeArea( child: SafeArea(
top: false, top: false,
bottom: model.isPatching, bottom: model.isPatching,
@ -84,7 +83,7 @@ class InstallerView extends StatelessWidget {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
onBackButtonPressed: () => model.onBackButtonInvoked(context), onBackButtonPressed: () => model.onWillPop(context),
bottom: PreferredSize( bottom: PreferredSize(
preferredSize: const Size(double.infinity, 1.0), preferredSize: const Size(double.infinity, 1.0),
child: GradientProgressIndicator(progress: model.progress), child: GradientProgressIndicator(progress: model.progress),
@ -112,6 +111,7 @@ class InstallerView extends StatelessWidget {
), ),
), ),
), ),
onWillPop: () => model.onWillPop(context),
), ),
); );
} }

View file

@ -489,38 +489,25 @@ class InstallerViewModel extends BaseViewModel {
} }
} }
bool canPop() { Future<bool> onWillPop(BuildContext context) async {
return !isPatching; if (isPatching) {
}
void onBackButtonInvoked(BuildContext context) {
if (canPop()) {
onPopInvoked(context, true);
} else {
onPopInvoked(context, false);
}
}
Future<void> onPopInvoked(BuildContext context, bool didPop) async {
if (didPop) {
if (!cancel) { if (!cancel) {
cleanPatcher(); cancel = true;
_toast.showBottom('installerView.pressBackAgain');
} else if (!isCanceled) {
await stopPatcher();
} else { } else {
_patcherAPI.cleanPatcher(); _toast.showBottom('installerView.noExit');
}
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');
}
} }
return false;
} }
if (!cancel) {
cleanPatcher();
} else {
_patcherAPI.cleanPatcher();
}
screenshotCallback.dispose();
Navigator.of(context).pop();
return true;
} }
} }

View file

@ -13,11 +13,13 @@ class NavigationView extends StatelessWidget {
return ViewModelBuilder<NavigationViewModel>.reactive( return ViewModelBuilder<NavigationViewModel>.reactive(
onViewModelReady: (model) => model.initialize(context), onViewModelReady: (model) => model.initialize(context),
viewModelBuilder: () => locator<NavigationViewModel>(), viewModelBuilder: () => locator<NavigationViewModel>(),
builder: (context, model, child) => PopScope( builder: (context, model, child) => WillPopScope(
canPop: model.currentIndex == 0, onWillPop: () async {
onPopInvoked: (bool didPop) { if (model.currentIndex == 0) {
if (!didPop) { return true;
} else {
model.setIndex(0); model.setIndex(0);
return false;
} }
}, },
child: Scaffold( child: Scaffold(