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 confirmAppExit( BuildContext context, { required bool cupertino, }) async { const title = Text('Close Pipelines?'); final leave = cupertino ? await showCupertinoDialog( 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( 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; }