From afd655f86dff84407eef073251ac1b0b4acaa9d6 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Thu, 29 Aug 2024 10:21:51 -0400 Subject: [PATCH] Support predictive back https://docs.flutter.dev/release/breaking-changes/android-predictive-back#migrating-a-back-confirmation-dialog --- lib/components/FormPage.dart | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/components/FormPage.dart b/lib/components/FormPage.dart index 34094df..9f41fd1 100644 --- a/lib/components/FormPage.dart +++ b/lib/components/FormPage.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:mobile_nebula/components/SimplePage.dart'; @@ -40,19 +38,17 @@ class _FormPageState extends State { Widget build(BuildContext context) { changed = widget.changed || changed; - return WillPopScope( - onWillPop: () { - if (!changed) { - return Future.value(true); + return PopScope( + canPop: false, + onPopInvoked: (bool didPop) async { + if (didPop) { + return; } - - var completer = Completer(); + final NavigatorState navigator = Navigator.of(context); Utils.confirmDelete(context, 'Discard changes?', () { - completer.complete(true); + navigator.pop(); }, deleteLabel: 'Yes', cancelLabel: 'No'); - - return completer.future; }, child: SimplePage( leadingAction: _buildLeader(context),