import 'dart:async'; import 'package:flutter/cupertino.dart'; Future alert(BuildContext context, String content, {String? title}) { var c = Completer(); showCupertinoDialog( context: context, builder: (context) => CupertinoAlertDialog( title: title != null ? Text(title) : null, content: Text(content), actions: [ CupertinoDialogAction( isDefaultAction: true, onPressed: () { c.complete(); Navigator.of(context).pop(); }, child: const Text("好"), ), ], ), ); return c.future; } Future confirm(BuildContext context, String content, {String? title, String? positiveText, String? negativeText}) { var c = Completer(); positiveText ??= "好"; negativeText ??= "取消"; showCupertinoDialog( context: context, builder: (context) => CupertinoAlertDialog( title: title != null ? Text(title) : null, content: Text(content), actions: [ CupertinoDialogAction( onPressed: () { Navigator.of(context).pop(); c.complete(false); }, child: Text(negativeText!), ), CupertinoDialogAction( isDefaultAction: true, onPressed: () { Navigator.of(context).pop(); c.complete(true); }, child: Text(positiveText!), ), ], ), ); return c.future; }