import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:kaer_with_panels/app/localization/kr_language_utils.dart'; import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart'; import 'package:kaer_with_panels/app/widgets/kr_local_image.dart'; /// 语言切换弹框组件 class KRLanguageSwitchDialog extends StatelessWidget { const KRLanguageSwitchDialog({super.key}); /// 显示语言切换弹框的静态方法 static Future kr_show() async { final isChineseRegion = await KRLanguageUtils.checkInitialLanguage(); if (isChineseRegion) { await Get.dialog( const KRLanguageSwitchDialog(), barrierDismissible: false, ); } } @override Widget build(BuildContext context) { return Dialog( backgroundColor: Colors.transparent, child: Container( width: 280.w, padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.h), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(24.r), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ // 图标 KrLocalImage( imageName: 'language_switch', width: 120.w, height: 120.h, ), SizedBox(height: 16.h), // 标题 Text( '根据您所在地区以及您的语言设置是否切换到中文语言?', textAlign: TextAlign.center, style: KrAppTextStyle( fontSize: 16, fontWeight: FontWeight.w500, color: Theme.of(context).textTheme.bodyMedium?.color, ), ), SizedBox(height: 24.h), // 切换按钮 _kr_buildButton( context: context, text: '切换', isPrimary: true, onTap: () async { final zhLanguage = KRLanguage.values.firstWhere( (lang) => lang.countryCode == 'zh', orElse: () => KRLanguage.zh, ); await KRLanguageUtils.switchLanguage(zhLanguage); Get.back(); }, ), SizedBox(height: 12.h), // 不切换按钮 _kr_buildButton( context: context, text: '不切换', isPrimary: false, onTap: () => Get.back(), ), ], ), ), ); } /// 构建按钮 Widget _kr_buildButton({ required BuildContext context, required String text, required bool isPrimary, required VoidCallback onTap, }) { return InkWell( onTap: onTap, child: Container( width: double.infinity, height: 44.h, decoration: BoxDecoration( color: isPrimary ? Colors.blue : Colors.transparent, borderRadius: BorderRadius.circular(22.r), border: isPrimary ? null : Border.all( color: Colors.blue, width: 1, ), ), alignment: Alignment.center, child: Text( text, style: KrAppTextStyle( fontSize: 16, fontWeight: FontWeight.w500, color: isPrimary ? Colors.white : Colors.blue, ), ), ), ); } }