Support predictive back
https://docs.flutter.dev/release/breaking-changes/android-predictive-back#migrating-a-back-confirmation-dialog
This commit is contained in:
parent
47e005bdf8
commit
afd655f86d
|
@ -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<FormPage> {
|
|||
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<bool>();
|
||||
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),
|
||||
|
|
Loading…
Reference in New Issue