You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
Dart
62 lines
1.5 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
Future<void> 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: <Widget>[
|
|
CupertinoDialogAction(
|
|
isDefaultAction: true,
|
|
onPressed: () {
|
|
c.complete();
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: const Text("好"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
return c.future;
|
|
}
|
|
|
|
Future<bool> confirm(BuildContext context, String content,
|
|
{String? title, String? positiveText, String? negativeText}) {
|
|
var c = Completer<bool>();
|
|
|
|
positiveText ??= "好";
|
|
negativeText ??= "取消";
|
|
|
|
showCupertinoDialog(
|
|
context: context,
|
|
builder: (context) => CupertinoAlertDialog(
|
|
title: title != null ? Text(title) : null,
|
|
content: Text(content),
|
|
actions: <Widget>[
|
|
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;
|
|
}
|