更新样式

This commit is contained in:
wyf
2025-12-01 15:41:34 +08:00
parent 991bf97fd1
commit 1cc26aa46d
18 changed files with 502 additions and 677 deletions

View File

@@ -281,476 +281,6 @@ Future showCitySelectionDialog(
);
}
// 加载中弹窗
Widget _buildLoadingDialog(ThemeController themeController) {
return Stack(
children: [
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Material(
color: Colors.transparent,
child: Dialog(
backgroundColor: themeController.currentColor.sc17,
insetPadding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(30.rpx, 40.rpx, 30.rpx, 90.rpx),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(
color: themeController.currentColor.sc2,
),
SizedBox(height: 20.rpx),
Text(
"加载中...".tr,
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: 28.rpx,
),
),
],
),
),
),
),
),
],
);
}
// 错误弹窗
Widget _buildErrorDialog(
ThemeController themeController, BuildContext context) {
return Stack(
children: [
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Material(
color: Colors.transparent,
child: Dialog(
backgroundColor: themeController.currentColor.sc17,
insetPadding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(30.rpx, 40.rpx, 30.rpx, 90.rpx),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"数据加载失败".tr,
style: TextStyle(
color: themeController.currentColor.sc3,
fontSize: 28.rpx,
),
),
SizedBox(height: 20.rpx),
ClickableContainer(
onTap: () => Navigator.of(context).pop(),
backgroundColor: Colors.transparent,
highlightColor: Colors.transparent,
padding: EdgeInsets.all(0),
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 30.rpx, vertical: 15.rpx),
decoration: BoxDecoration(
color: themeController.currentColor.sc2,
borderRadius: BorderRadius.circular(8.rpx),
),
child: Text(
"关闭".tr,
style: TextStyle(
color: Colors.white,
fontSize: 28.rpx,
),
),
),
),
],
),
),
),
),
),
],
);
}
// 城市选择器弹窗
Widget _buildCityPickerDialog(
BuildContext context,
ThemeController themeController,
bool isChinese,
String title,
List<CityModel> cityData,
Function? onCityChanged, {
required RxList<String> countries,
required RxList<String> provinces,
required RxList<String> cities,
required RxInt countryIndex,
required RxInt provinceIndex,
required RxInt cityIndex,
}) {
// 内部更新方法
void updateCities() {
try {
if (provinces.isEmpty || countries.isEmpty) return;
final selectedCountry = countries[countryIndex.value];
final selectedProvince = provinces[provinceIndex.value];
for (var country in cityData) {
if (country.value == selectedCountry) {
for (var province in country.children ?? []) {
if (province.value == selectedProvince) {
// 安全地处理城市列表
final cityList = (province.children ?? [])
.map((city) => city?.value ?? city?.city ?? '')
.where((cityName) =>
(cityName as String).isNotEmpty) // 明确转换为 String
.toList()
.cast<String>();
cities.value = cityList;
cityIndex.value = cities.isNotEmpty ? 0 : 0;
return;
}
}
}
}
cities.value = [];
cityIndex.value = 0;
} catch (e) {
ef.log("更新城市列表失败:$e");
cities.value = [];
cityIndex.value = 0;
}
}
void updateProvinces() {
try {
if (countries.isEmpty) return;
final selectedCountry = countries[countryIndex.value];
for (var country in cityData) {
if (country.value == selectedCountry) {
// 安全地处理省份列表
final provinceList = (country.children ?? [])
.map((province) => province?.value ?? province?.province ?? '')
.where((provinceName) => provinceName.isNotEmpty)
.toList()
.cast<String>();
provinces.value = provinceList;
provinceIndex.value = provinces.isNotEmpty ? 0 : 0;
// 更新城市
updateCities();
return;
}
}
provinces.value = [];
provinceIndex.value = 0;
cities.value = [];
cityIndex.value = 0;
} catch (e) {
ef.log("更新省份列表失败:$e");
provinces.value = [];
provinceIndex.value = 0;
cities.value = [];
cityIndex.value = 0;
}
}
CityModel? getSelectedCityData() {
try {
if (countries.isEmpty) return null;
final selectedCountry = countries[countryIndex.value];
// 查找匹配的国家
for (var country in cityData) {
final countryName = country.value ?? country.country;
if (countryName == selectedCountry) {
// 情况1: 只有国家一级(没有省份和城市)
if ((country.children == null || country.children!.isEmpty) &&
(country.city != null || country.value != null)) {
return country; // 直接返回国家数据
}
// 情况2: 有省份但没有城市数据
if (provinces.isNotEmpty && provinceIndex.value < provinces.length) {
final selectedProvince = provinces[provinceIndex.value];
for (var province in country.children ?? []) {
final provinceName = province.value ?? province.province;
if (provinceName == selectedProvince) {
// 情况2.1: 省份有城市数据
if (cities.isNotEmpty && cityIndex.value < cities.length) {
final selectedCityName = cities[cityIndex.value];
for (var city in province.children ?? []) {
final cityName = city.value ?? city.city;
if (cityName == selectedCityName) {
return city; // 返回城市数据
}
}
}
// 情况2.2: 省份没有城市数据,但省份本身有信息
if ((province.children == null || province.children!.isEmpty) &&
(province.city != null || province.value != null)) {
return province; // 返回省份数据
}
}
}
}
// 情况3: 有省份但没有选择具体省份,返回国家数据
return country;
}
}
return null;
} catch (e) {
ef.log("获取选中城市数据失败:$e");
return null;
}
}
return Scaffold(
resizeToAvoidBottomInset: false, // 在这里也设置
backgroundColor: Colors.transparent,
body: Stack(
children: [
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Material(
color: Colors.transparent,
child: Dialog(
backgroundColor: themeController.currentColor.sc17,
insetPadding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(30.rpx, 10.rpx, 30.rpx, 0.rpx),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: Colors.transparent,
padding: EdgeInsets.zero,
onTap: () => Navigator.of(context).pop(),
child: Container(
width: 110.rpx,
height: 60.rpx,
alignment: Alignment.center,
child: Text("取消".tr,
style: TextStyle(
fontSize: 30.rpx, color: Colors.white)),
),
),
Text(
title,
style: TextStyle(
fontFamily: 'Readex Pro',
color: themeController.currentColor.sc3,
fontSize: 30.rpx,
),
),
Obx(() {
CityModelController cityModelController = Get.find();
cityModelController.tmp;
ef.log("${cityModelController.tmp.value}");
return ClickableContainer(
backgroundColor: Colors.transparent,
highlightColor: Colors.transparent,
padding: EdgeInsets.zero,
// onTap: () {
// final selectedCityData = getSelectedCityData();
// if (selectedCityData != null) {
// onCityChanged?.call(selectedCityData);
// }
// Navigator.of(context).pop();
// },
onTap: () {
final selectedCityData = getSelectedCityData();
if (selectedCityData != null) {
// 根据ID查找完整的层级数据并补全
final fullCityData = findCompleteCityDataById(
selectedCityData.id, cityData);
if (fullCityData != null) {
// 使用完整的数据
onCityChanged?.call(fullCityData);
} else {
// 如果没有找到完整数据,使用当前选中的数据
onCityChanged?.call(selectedCityData);
}
}
Navigator.of(context).pop();
},
child: Container(
width: 110.rpx,
height: 60.rpx,
alignment: Alignment.center,
child: Text("确定".tr,
style: TextStyle(
fontSize: 30.rpx,
color: themeController.currentColor.sc2,
)),
),
);
}),
],
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0),
child: ListSearchWidget(
keyword: cityModelController.model.keyword,
color: cityModelController.model.color,
hint: "输入国家、省份或城市".tr,
onChange: (d) {
cityModelController.model.keyword = d;
// 实时搜索
cityModelController.searchCities(d);
},
findCallback: () {
// 点击搜索按钮时搜索
cityModelController.searchCities(
cityModelController.model.keyword ?? "");
},
padding: EdgeInsets.fromLTRB(
0.rpx,
30.rpx,
0.rpx,
10.rpx,
),
showResultList: true, // 开启结果列表
searchResults:
cityModelController.searchResults, // 搜索结果
onResultTap: (result) {
// 处理选择结果
final selectedCity =
cityModelController.getCityByDisplayName(result);
if (selectedCity != null) {
final fullCityData = findCompleteCityDataById(
selectedCity.id, cityData);
// 更新选中的城市
PersonController personController = Get.find();
personController.cityModel = fullCityData;
personController.updateAll();
ef.log("选择了城市: ${selectedCity.displayName}");
// 关闭弹窗(如果是在弹窗中使用)
Navigator.of(context).pop();
}
},
),
),
SizedBox(height: 20.rpx),
Stack(
children: [
Positioned.fill(
child: IgnorePointer(
child: Center(
child: Container(
height: 90.rpx,
margin: EdgeInsets.symmetric(horizontal: 0.rpx),
decoration: BoxDecoration(
color: themeController.currentColor.sc2,
borderRadius: BorderRadius.circular(16.rpx),
),
),
),
),
),
Container(
child: Padding(
padding: EdgeInsets.fromLTRB(20.rpx, 0, 20.rpx, 0),
child: Row(
children: [
Expanded(
child: Obx(() {
CityModelController cityModelController =
Get.find();
cityModelController.tmp;
ef.log("${cityModelController.tmp.value}");
return getOnePickers(
context,
countries,
countryIndex,
unit: "",
onChanged: (_) => updateProvinces(),
);
}),
),
Expanded(
child: Obx(() {
CityModelController cityModelController =
Get.find();
cityModelController.tmp;
ef.log("${cityModelController.tmp.value}");
return getOnePickers(
context,
provinces,
provinceIndex,
unit: "",
onChanged: (_) => updateCities(),
);
}),
),
Expanded(
child: Obx(() {
CityModelController cityModelController =
Get.find();
cityModelController.tmp;
ef.log("${cityModelController.tmp.value}");
return getOnePickers(
context,
cities,
cityIndex,
unit: "",
);
}),
),
],
),
),
),
],
),
],
),
),
),
),
),
],
),
);
}
// 根据ID查找完整的城市数据包含国家、省份、城市信息
CityModel? findCompleteCityDataById(int? id, List<CityModel> cityData) {
if (id == null) return null;
@@ -1095,6 +625,8 @@ Widget _buildCityPickerContent(
countryIndex,
unit: "",
onChanged: (_) => updateProvinces(),
pickerKey: ValueKey(
'country_${DateTime.now().millisecondsSinceEpoch}'), // 添加动态 key
);
}),
),
@@ -1110,6 +642,8 @@ Widget _buildCityPickerContent(
provinceIndex,
unit: "",
onChanged: (_) => updateCities(),
pickerKey: ValueKey(
'province_${DateTime.now().millisecondsSinceEpoch}'), // 添加动态 key
);
}),
),
@@ -1124,6 +658,8 @@ Widget _buildCityPickerContent(
cities,
cityIndex,
unit: "",
pickerKey: ValueKey(
'city_${DateTime.now().millisecondsSinceEpoch}'), // 添加动态 key
);
}),
),