34 lines
982 B
Dart
34 lines
982 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../core/localization/app_localizations.dart';
|
|
import 'capsule_toast.dart';
|
|
|
|
enum LegalDocument {
|
|
privacy('my.privacy_policy', 'https://ri.satabot.com/web/legal/privacy.html'),
|
|
terms('my.user_agreement', 'https://ri.satabot.com/web/legal/terms.html');
|
|
|
|
const LegalDocument(this.titleKey, this.url);
|
|
|
|
final String titleKey;
|
|
final String url;
|
|
}
|
|
|
|
Future<void> openLegalDocument(
|
|
BuildContext context,
|
|
LegalDocument document,
|
|
) async {
|
|
final errorText = AppLocalizations.of(context).translate('legal.open_failed');
|
|
try {
|
|
final opened = await launchUrl(
|
|
Uri.parse(document.url),
|
|
mode: LaunchMode.inAppBrowserView,
|
|
webOnlyWindowName: '_blank',
|
|
);
|
|
if (opened) return;
|
|
} catch (_) {
|
|
// 平台无法打开时保留当前页面,并向用户提供重试提示。
|
|
}
|
|
if (context.mounted) CapsuleToast.show(errorText, showCheck: false);
|
|
}
|