onWillPop method
Standard warning dialog for leaving a source page. All sources should use this and wrap their build function with a WillPopScope.
Implementation
Future<bool> onWillPop() async {
Widget alertDialog = AlertDialog(
shape: const RoundedRectangleBorder(),
title: Text(t.exit_media_title),
content: Text(t.exit_media_description),
actions: <Widget>[
TextButton(
child: Text(
t.dialog_exit,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
),
onPressed: () async {
await onSourcePagePop();
if (mounted) {
Navigator.pop(context, true);
}
await appModel.closeMedia(
context: context,
ref: ref,
mediaSource: appModel.currentMediaSource!,
item: widget.item,
);
}),
TextButton(
child: Text(
t.dialog_cancel,
),
onPressed: () => Navigator.pop(context, false),
),
],
);
return await showDialog(
context: context,
builder: (context) => alertDialog,
) ??
false;
}