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.

97 lines
2.6 KiB
Dart

2 years ago
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_web_browser/flutter_web_browser.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
import '../styles.dart';
2 years ago
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,
2 years ago
{String? title,
String? positiveText,
String? negativeText,
bool isDanger = false}) {
2 years ago
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(
isDestructiveAction: isDanger,
isDefaultAction: !isDanger,
2 years ago
onPressed: () {
Navigator.of(context).pop();
c.complete(true);
},
child: Text(positiveText!),
),
],
),
);
return c.future;
}
Future<void> openUrl(String url, {bool inApp = false}) async {
if (!kIsWeb && inApp) {
// APP部分
if (GetPlatform.isAndroid || GetPlatform.isIOS) {
// 安卓和IOS使用应用内浏览器打开
await FlutterWebBrowser.openWebPage(
url: url,
customTabsOptions: const CustomTabsOptions(
defaultColorSchemeParams: CustomTabsColorSchemeParams(
toolbarColor: Styles.websiteNavbarColor,
),
shareState: CustomTabsShareState.off,
showTitle: true,
),
safariVCOptions: const SafariViewControllerOptions(
barCollapsingEnabled: true,
));
return;
}
}
// 其他平台直接调用浏览器打开
2 years ago
launchUrlString(url, mode: LaunchMode.externalApplication);
}