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/cupertino.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:mobile_nebula/components/SimplePage.dart';
|
import 'package:mobile_nebula/components/SimplePage.dart';
|
||||||
|
@ -40,19 +38,17 @@ class _FormPageState extends State<FormPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
changed = widget.changed || changed;
|
changed = widget.changed || changed;
|
||||||
|
|
||||||
return WillPopScope(
|
return PopScope(
|
||||||
onWillPop: () {
|
canPop: false,
|
||||||
if (!changed) {
|
onPopInvoked: (bool didPop) async {
|
||||||
return Future.value(true);
|
if (didPop) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
final NavigatorState navigator = Navigator.of(context);
|
||||||
var completer = Completer<bool>();
|
|
||||||
|
|
||||||
Utils.confirmDelete(context, 'Discard changes?', () {
|
Utils.confirmDelete(context, 'Discard changes?', () {
|
||||||
completer.complete(true);
|
navigator.pop();
|
||||||
}, deleteLabel: 'Yes', cancelLabel: 'No');
|
}, deleteLabel: 'Yes', cancelLabel: 'No');
|
||||||
|
|
||||||
return completer.future;
|
|
||||||
},
|
},
|
||||||
child: SimplePage(
|
child: SimplePage(
|
||||||
leadingAction: _buildLeader(context),
|
leadingAction: _buildLeader(context),
|
||||||
|
|
Loading…
Reference in New Issue