初始化提交
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/kr_country_selector_controller.dart';
|
||||
|
||||
class KRCountrySelectorBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<KRCountrySelectorController>(
|
||||
() => KRCountrySelectorController(),
|
||||
);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kaer_with_panels/app/common/app_config.dart';
|
||||
import 'package:kaer_with_panels/app/utils/kr_country_util.dart';
|
||||
|
||||
import '../../../services/singbox_imp/kr_sing_box_imp.dart';
|
||||
|
||||
class KRCountrySelectorController extends GetxController {
|
||||
// 使用 KRCountry 枚举来加载国家
|
||||
final RxList<KRCountry> kr_countries = <KRCountry>[].obs;
|
||||
// 当前选中的国家
|
||||
final Rx<KRCountry> kr_selectedCountry = KRCountry.cn.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
kr_selectedCountry.value = KRCountryUtil.kr_currentCountry.value;
|
||||
kr_loadCountries();
|
||||
}
|
||||
|
||||
// 加载国家数据
|
||||
void kr_loadCountries() {
|
||||
kr_countries.value = KRCountryUtil.kr_getSupportedCountries();
|
||||
|
||||
}
|
||||
|
||||
// 选择国家
|
||||
Future<void> kr_selectCountry(KRCountry country) async {
|
||||
kr_selectedCountry.value = country;
|
||||
// try {
|
||||
// await KRSingBoxImp().kr_updateCountry(country);
|
||||
// // Get.back();
|
||||
// } catch (err) {
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
KRSingBoxImp().kr_updateCountry(kr_selectedCountry.value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:kaer_with_panels/app/localization/app_translations.dart';
|
||||
|
||||
import 'package:kaer_with_panels/app/utils/kr_country_util.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_country_flag.dart';
|
||||
import '../controllers/kr_country_selector_controller.dart';
|
||||
|
||||
class KRCountrySelectorView extends GetView<KRCountrySelectorController> {
|
||||
const KRCountrySelectorView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color.fromRGBO(23, 151, 255, 0.15), // 渐变开始颜色
|
||||
Color.fromRGBO(23, 151, 255, 0.05), // 中间过渡颜色
|
||||
// 非渐变色区域
|
||||
],
|
||||
stops: [0.0, 0.28], // 调整渐变结束位置
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_back_ios,
|
||||
size: 20.r,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
title: Text(
|
||||
AppTranslations.kr_setting.countrySelector,
|
||||
style: KrAppTextStyle(
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => ListView.separated(
|
||||
padding: EdgeInsets.all(16.r),
|
||||
itemCount: controller.kr_countries.length,
|
||||
separatorBuilder: (context, index) => SizedBox(height: 12.h),
|
||||
itemBuilder: (context, index) {
|
||||
final country = controller.kr_countries[index];
|
||||
return _kr_buildCountryCard(country, context);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 构建国家卡片
|
||||
Widget _kr_buildCountryCard(KRCountry country, BuildContext context) {
|
||||
return Obx(
|
||||
() => InkWell(
|
||||
onTap: () => controller.kr_selectCountry(country),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16.r),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(12.r),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 国家图标
|
||||
KRCountryFlag(
|
||||
countryCode: country.kr_code,
|
||||
width: 24.r,
|
||||
height: 24.r,
|
||||
),
|
||||
SizedBox(width: 12.w),
|
||||
// 国家名称
|
||||
Text(
|
||||
KRCountryUtil.kr_getCountryName(country),
|
||||
style: KrAppTextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// 选中标记
|
||||
if (controller.kr_selectedCountry.value == country)
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.blue,
|
||||
size: 20.r,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user