Browse Source

feat(utils): 添加文档URL助手以支持多语言文档链接

新增 doc_url_helper.dart 工具文件,提供 docLangPath、privacyPolicyUrl 和 userAgreementUrl 函数
根据当前语言环境动态生成对应的文档链接,支持多种语言版本
替换登录页、个人资料页和隐私政策弹窗中的硬编码URL,提高代码复用性和可维护性
newdev_shunjiawei
lxm 7 months ago
parent
commit
8318aa8f79
  1. 27
      lib/core/utils/doc_url_helper.dart
  2. 19
      lib/modules/common/widgets/privacy_policy_dialog.dart
  3. 16
      lib/modules/login/views/login_view.dart
  4. 19
      lib/modules/profile/views/profile_view.dart

27
lib/core/utils/doc_url_helper.dart

@ -0,0 +1,27 @@
import 'package:get/get.dart';
/// 根据当前语言返回 doc 目录名,如 "zh_cn"、"en"、"fr"
String docLangPath() {
final lang = Get.locale?.languageCode ?? 'en';
final country = Get.locale?.countryCode?.toUpperCase() ?? '';
if (lang == 'zh') {
if (country == 'CN') return 'zh_cn';
if (country == 'HK') return 'zh_hk';
return 'zh_tw';
}
const supported = [
'ar', 'bg', 'cs', 'da', 'de', 'el', 'es', 'et', 'fa', 'fi', 'fr',
'hi', 'hr', 'hu', 'id', 'is', 'it', 'ja', 'ko', 'lt', 'lv', 'ms',
'nb', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'th',
'tl', 'tr', 'uk', 'vi',
];
return supported.contains(lang) ? lang : 'en';
}
/// 构建隐私政策 URL
String privacyPolicyUrl() =>
'https://www.voitrans.net/doc/${docLangPath()}/privacy_policy.html';
/// 构建用户协议 URL
String userAgreementUrl() =>
'https://www.voitrans.net/doc/${docLangPath()}/user_agreement.html';

19
lib/modules/common/widgets/privacy_policy_dialog.dart

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../webview_page.dart';
import '../../../core/utils/doc_url_helper.dart';
/// 隐私政策弹窗组件
class PrivacyPolicyDialog extends StatelessWidget {
@ -77,15 +78,8 @@ class PrivacyPolicyDialog extends StatelessWidget {
alignment: PlaceholderAlignment.middle,
child: GestureDetector(
onTap: () {
String url =
'https://www.voitrans.net/doc/privacy_policy.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url =
'https://www.voitrans.net/doc/privacy_policy_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: privacyPolicyUrl(),
title: 'privacyPolicy'.tr,
));
},
@ -109,15 +103,8 @@ class PrivacyPolicyDialog extends StatelessWidget {
alignment: PlaceholderAlignment.middle,
child: GestureDetector(
onTap: () {
String url =
'https://www.voitrans.net/doc/user_agreement.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url =
'https://www.voitrans.net/doc/user_agreement_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: userAgreementUrl(),
title: 'userAgreement'.tr, // 用户协议
));
},

16
lib/modules/login/views/login_view.dart

@ -4,6 +4,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../controllers/login_controller.dart';
import '../../common/webview_page.dart';
import '../../../core/utils/doc_url_helper.dart';
class LoginView extends GetView<LoginController> {
const LoginView({Key? key}) : super(key: key);
@ -596,13 +597,8 @@ class LoginView extends GetView<LoginController> {
children: [
GestureDetector(
onTap: () {
String url = 'https://www.voitrans.net/doc/user_agreement.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url = 'https://www.voitrans.net/doc/user_agreement_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: userAgreementUrl(),
title: 'userAgreement'.tr,
));
},
@ -623,14 +619,8 @@ class LoginView extends GetView<LoginController> {
),
GestureDetector(
onTap: () {
String url = 'https://www.voitrans.net/doc/privacy_policy.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url = 'https://www.voitrans.net/doc/privacy_policy_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: privacyPolicyUrl(),
title: 'privacyPolicy'.tr,
));
},

19
lib/modules/profile/views/profile_view.dart

@ -7,6 +7,7 @@ import '../../../routes/app_routes.dart';
import 'dart:io';
import 'dart:ui';
import '../../common/webview_page.dart';
import '../../../core/utils/doc_url_helper.dart';
import 'unified_avatar.dart';
// ProfileView: 用户设置页面
@ -695,15 +696,8 @@ class EditProfileView extends GetView<ProfileController> {
isDarkMode ? Colors.purple[300]! : Colors.purple[600]!,
titleColor: isDarkMode ? Colors.white : Colors.black87,
onTap: () {
String url =
'https://www.voitrans.net/doc/user_agreement.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url =
'https://www.voitrans.net/doc/user_agreement_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: userAgreementUrl(),
title: 'userAgreement'.tr,
));
},
@ -726,15 +720,8 @@ class EditProfileView extends GetView<ProfileController> {
isDarkMode ? Colors.purple[300]! : Colors.purple[600]!,
titleColor: isDarkMode ? Colors.white : Colors.black87,
onTap: () {
String url =
'https://www.voitrans.net/doc/privacy_policy.html';
if (Get.locale?.languageCode != 'zh' ||
Get.locale?.countryCode != 'CN') {
url =
'https://www.voitrans.net/doc/privacy_policy_en.html';
}
Get.to(() => WebViewPage(
url: url,
url: privacyPolicyUrl(),
title: 'privacyPolicy'.tr,
));
},

Loading…
Cancel
Save