| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- import 'package:get/get.dart';
- import 'package:url_launcher/url_launcher.dart';
- import '../app/components/ix_snackbar.dart';
- import '../app/constants/configs.dart';
- import '../app/data/sp/ix_sp.dart';
- import '../app/routes/app_pages.dart';
- import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as ct;
- import '../config/translations/strings_enum.dart';
- class SystemHelper {
- // static Future<void> openEmail(String email) async {
- // final Uri emailUri = Uri(
- // scheme: 'mailto',
- // path: email,
- // );
- // try {
- // await launchUrl(
- // emailUri,
- // mode: LaunchMode.externalApplication,
- // );
- // } catch (e) {
- // CustomSnackBar.showCustomErrorSnackBar(
- // title: Strings.error.tr, message: Strings.eUtilOpenEmail.tr);
- // }
- // }
- static Future<void> openGooglePlay(String packageName) async {
- final String url =
- 'https://play.google.com/store/apps/details?id=$packageName';
- try {
- // 直接尝试打开 Google Play 应用
- await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
- } catch (e) {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.eUtilOpenGooglePlay.tr,
- );
- }
- }
- static Future<void> openGooglePlayUrl(String url) async {
- try {
- // 直接尝试打开 Google Play 应用
- await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
- } catch (e) {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.eUtilOpenGooglePlay.tr,
- );
- }
- }
- static Future<void> openGoogleChrome(String url) async {
- try {
- await ct.launchUrl(
- Uri.parse(url),
- customTabsOptions: ct.CustomTabsOptions.partial(
- configuration: ct.PartialCustomTabsConfiguration.adaptiveSheet(
- initialHeight: Get.height * 0.7,
- initialWidth: Get.width * 0.4,
- activitySideSheetMaximizationEnabled: true,
- activitySideSheetDecorationType:
- ct.CustomTabsActivitySideSheetDecorationType.shadow,
- activitySideSheetRoundedCornersPosition:
- ct.CustomTabsActivitySideSheetRoundedCornersPosition.top,
- cornerRadius: 16,
- ),
- ),
- safariVCOptions: const ct.SafariViewControllerOptions.pageSheet(
- configuration: ct.SheetPresentationControllerConfiguration(
- detents: {
- ct.SheetPresentationControllerDetent.large,
- ct.SheetPresentationControllerDetent.medium,
- },
- prefersScrollingExpandsWhenScrolledToEdge: true,
- prefersGrabberVisible: true,
- prefersEdgeAttachedInCompactHeight: true,
- ),
- dismissButtonStyle: ct.SafariViewControllerDismissButtonStyle.close,
- ),
- );
- } catch (e) {
- try {
- await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);
- } catch (e) {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.eUtilOpenBrowser.tr,
- );
- }
- }
- }
- static Future<void> closeGoogleChrome() async {
- await ct.closeCustomTabs();
- }
- static Future<void> openWebPage(String url) async {
- try {
- final Uri webUri = Uri.parse(url);
- await launchUrl(webUri, mode: LaunchMode.externalApplication);
- } catch (e) {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.eUtilOpenBrowser.tr,
- );
- }
- }
- static Future<void> openInAppWebPage(String url, String title) async {
- Get.toNamed(Routes.WEB, arguments: {'url': url, 'title': title});
- }
- static Future<void> handleDeepLink(String deepLink) async {
- try {
- final Uri uri = Uri.parse(deepLink);
- if (await canLaunchUrl(uri)) {
- await launchUrl(uri, mode: LaunchMode.externalApplication);
- } else {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.unknownError.tr,
- );
- }
- } catch (e) {
- IXSnackBar.showIXErrorSnackBar(
- title: Strings.error.tr,
- message: Strings.unknownError.tr,
- );
- }
- }
- static void openPrivacyTerms() {
- final launch = IXSP.getLaunch();
- if (launch?.appConfig?.privacyAgreement != null &&
- launch?.appConfig?.privacyAgreement?.privacyTermsUrl != null) {
- String url = launch?.appConfig?.privacyAgreement?.privacyTermsUrl ?? '';
- if (url.indexOf("http") != 0) {
- url = '${Configs.websiteUrl}/$url';
- }
- Get.toNamed(
- Routes.WEB,
- arguments: {'url': url, 'title': Strings.privacyPolicy.tr},
- );
- } else {
- Get.toNamed(
- Routes.MARKDOWN,
- arguments: {'title': Strings.privacyPolicy.tr, 'filename': 'privacy'},
- );
- }
- }
- static void openTermsOfService() {
- final launch = IXSP.getLaunch();
- if (launch?.appConfig?.privacyAgreement != null &&
- launch?.appConfig?.privacyAgreement?.termsOfServiceUrl != null) {
- String url = launch?.appConfig?.privacyAgreement?.termsOfServiceUrl ?? '';
- if (url.indexOf("http") != 0) {
- url = '${Configs.websiteUrl}/$url';
- }
- Get.toNamed(
- Routes.WEB,
- arguments: {'url': url, 'title': Strings.termsOfService.tr},
- );
- } else {
- Get.toNamed(
- Routes.MARKDOWN,
- arguments: {'title': Strings.termsOfService.tr, 'filename': 'terms'},
- );
- }
- }
- // 打开 JS Bridge 测试页面
- static void openTestPage() {
- Get.toNamed(
- Routes.WEB,
- arguments: {
- // 使用 assets/ 前缀,WebView 会自动使用 loadData 加载
- 'url': 'assets/html/test_jsbridge.html',
- 'title': 'JS Bridge 测试',
- 'fullScreen': true,
- },
- );
- }
- }
|