更新城市选择

This commit is contained in:
wyf
2025-11-21 10:34:18 +08:00
parent b2a621c2d3
commit 991bf97fd1
27 changed files with 79242 additions and 467 deletions

View File

@@ -6,6 +6,7 @@ import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/color/app_uri_status.dart';
import 'package:vbvs_app/common/pojo/city.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
@@ -18,6 +19,7 @@ import 'package:vbvs_app/controller/person/person_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/pages/person/select_city.dart';
import 'package:vbvs_app/pages/person/select_time.dart';
class PersonPage extends StatefulWidget {
@@ -34,6 +36,9 @@ class _EPageState extends State<PersonPage> {
PersonController personController = Get.find();
ThemeController themeController = Get.find();
final CityModelController cityController = Get.find<CityModelController>();
late Future<List<CityModel>> cityDataFuture;
@override
void initState() {
super.initState();
@@ -55,6 +60,10 @@ class _EPageState extends State<PersonPage> {
personController.weight.value = "";
personController.height.value = "";
personController.dateTime = null;
cityDataFuture = cityController.loadAndSetCityData().then((success) {
return cityController.cityList;
});
}
@override
@@ -533,6 +542,65 @@ class _EPageState extends State<PersonPage> {
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
70.rpx, 50.rpx, 70.rpx, 0),
child: Container(
height: 100.rpx,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.rpx),
border: Border.all(
color: themeController.currentColor.sc4
.withOpacity(0.5),
width: AppConstants().border_width,
),
),
child: InkWell(
onTap: () {
FocusScope.of(context)
.requestFocus(FocusNode());
Future.delayed(Duration(milliseconds: 250),
() {
// 使用当前选中的城市数据,如果没有则创建默认
CityModel currentCity =
personController.cityModel ??
CityModel();
showCitySelectionDialog(
context,
selectedCity: currentCity,
onCityChanged: (CityModel newCity) {
// 处理城市选择变化
print(
'Selected city: ${newCity.toJson()}');
personController.cityModel = newCity;
personController.updateAll();
},
title: "选择城市".tr,
cityDataFuture:
cityDataFuture, // 传入预加载的数据
);
});
},
child: Center(
child: Text(
_getDetailedCityDisplayText(
personController.cityModel),
textAlign: TextAlign.right,
style: TextStyle(
fontFamily: 'Readex Pro',
color: personController.cityModel !=
null
? themeController.currentColor.sc3
: themeController.currentColor.sc4,
fontSize:
AppConstants().normal_text_fontSize,
letterSpacing: 0,
),
),
),
),
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0, 117.rpx, 0, 0),
@@ -696,6 +764,29 @@ class _EPageState extends State<PersonPage> {
),
);
}
String _getDetailedCityDisplayText(CityModel? cityModel) {
if (cityModel == null) {
return '选择城市'.tr;
}
// 根据数据层级显示不同的格式
if (cityModel.city != null && cityModel.city!.isNotEmpty) {
// 三级数据:国家-省份-城市
return '${cityModel.country ?? ''}-${cityModel.province ?? ''}-${cityModel.city ?? cityModel.value ?? ''}';
} else if (cityModel.province != null && cityModel.province!.isNotEmpty) {
// 二级数据:国家-省份
return '${cityModel.country ?? ''}-${cityModel.province ?? cityModel.value ?? ''}';
} else if (cityModel.country != null && cityModel.country!.isNotEmpty) {
// 一级数据:国家
return cityModel.country!;
} else if (cityModel.value != null && cityModel.value!.isNotEmpty) {
// 只有 value 字段
return cityModel.value!;
} else {
return '选择城市'.tr;
}
}
}
void updateDeviceBindStatus(String mac) {