Files
pipelines/app/lib/application/app_exit_dialog.dart
T

50 lines
1.6 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Asks before Back leaves the app from the top of a tab. True to leave.
Future<bool> confirmAppExit(
BuildContext context, {
required bool cupertino,
}) async {
const title = Text('Close Pipelines?');
final leave = cupertino
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: title,
actions: [
CupertinoDialogAction(
key: const Key('app-exit-stay'),
isDefaultAction: true,
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Stay'),
),
CupertinoDialogAction(
key: const Key('app-exit-close'),
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Close'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: title,
actions: [
TextButton(
key: const Key('app-exit-stay'),
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Stay'),
),
FilledButton(
key: const Key('app-exit-close'),
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Close'),
),
],
),
);
return leave ?? false;
}