更新眠花糖选择城市
This commit is contained in:
@@ -37,16 +37,35 @@ Future<List<CityModel>> loadCityData() async {
|
||||
}
|
||||
}
|
||||
|
||||
// 定义城市选择器颜色配置
|
||||
class CitySelectionColors {
|
||||
final Color? pickerBackgroundColor; // 选择器整体背景色
|
||||
final Color? confirmTextColor; // 确定按钮文字颜色
|
||||
final Color? selectedCityColor; // 选中的城市背景色
|
||||
|
||||
const CitySelectionColors({
|
||||
this.pickerBackgroundColor,
|
||||
this.confirmTextColor,
|
||||
this.selectedCityColor,
|
||||
});
|
||||
}
|
||||
|
||||
Future showCitySelectionDialog(
|
||||
BuildContext context, {
|
||||
required CityModel selectedCity,
|
||||
Function? onCityChanged,
|
||||
String title = "选择城市",
|
||||
required Future<List<CityModel>> cityDataFuture, // 改为required参数
|
||||
CitySelectionColors? colors, // 新增:颜色配置参数
|
||||
}) {
|
||||
ThemeController themeController = Get.find();
|
||||
final bool isChinese = Get.locale?.languageCode == 'zh' ?? true;
|
||||
|
||||
// 使用传入的颜色,如果没传则使用主题颜色
|
||||
final Color pickerBackgroundColor = colors?.pickerBackgroundColor ?? themeController.currentColor.sc17;
|
||||
final Color confirmTextColor = colors?.confirmTextColor ?? themeController.currentColor.sc2;
|
||||
final Color selectedCityColor = colors?.selectedCityColor ?? themeController.currentColor.sc2;
|
||||
|
||||
final RxList<String> countries = <String>[].obs;
|
||||
final RxList<String> provinces = <String>[].obs;
|
||||
final RxList<String> cities = <String>[].obs;
|
||||
@@ -243,12 +262,21 @@ Future showCitySelectionDialog(
|
||||
builder: (context, snapshot) {
|
||||
// 数据加载中
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return _buildLoadingBottomSheet(themeController);
|
||||
return _buildLoadingBottomSheet(
|
||||
themeController,
|
||||
pickerBackgroundColor,
|
||||
confirmTextColor,
|
||||
);
|
||||
}
|
||||
|
||||
// 数据加载错误
|
||||
if (snapshot.hasError || !snapshot.hasData) {
|
||||
return _buildErrorBottomSheet(themeController, context);
|
||||
return _buildErrorBottomSheet(
|
||||
themeController,
|
||||
context,
|
||||
pickerBackgroundColor,
|
||||
confirmTextColor,
|
||||
);
|
||||
}
|
||||
|
||||
final cityData = snapshot.data!;
|
||||
@@ -265,6 +293,9 @@ Future showCitySelectionDialog(
|
||||
title,
|
||||
cityData,
|
||||
onCityChanged,
|
||||
pickerBackgroundColor: pickerBackgroundColor,
|
||||
confirmTextColor: confirmTextColor,
|
||||
selectedCityColor: selectedCityColor,
|
||||
countries: countries,
|
||||
provinces: provinces,
|
||||
cities: cities,
|
||||
@@ -350,6 +381,9 @@ Widget _buildCityPickerContent(
|
||||
String title,
|
||||
List<CityModel> cityData,
|
||||
Function? onCityChanged, {
|
||||
required Color pickerBackgroundColor,
|
||||
required Color confirmTextColor,
|
||||
required Color selectedCityColor,
|
||||
required RxList<String> countries,
|
||||
required RxList<String> provinces,
|
||||
required RxList<String> cities,
|
||||
@@ -481,7 +515,7 @@ Widget _buildCityPickerContent(
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc17,
|
||||
color: pickerBackgroundColor, // 使用传入的选择器整体颜色
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20.rpx),
|
||||
topRight: Radius.circular(20.rpx),
|
||||
@@ -549,7 +583,7 @@ Widget _buildCityPickerContent(
|
||||
child: Text("确定".tr,
|
||||
style: TextStyle(
|
||||
fontSize: 30.rpx,
|
||||
color: themeController.currentColor.sc2,
|
||||
color: confirmTextColor, // 使用传入的确定文字颜色
|
||||
)),
|
||||
),
|
||||
);
|
||||
@@ -600,7 +634,7 @@ Widget _buildCityPickerContent(
|
||||
height: 90.rpx,
|
||||
margin: EdgeInsets.symmetric(horizontal: 0.rpx),
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc2,
|
||||
color: selectedCityColor, // 使用传入的选中城市颜色
|
||||
borderRadius: BorderRadius.circular(16.rpx),
|
||||
),
|
||||
),
|
||||
@@ -677,11 +711,15 @@ Widget _buildCityPickerContent(
|
||||
}
|
||||
|
||||
// 加载中 BottomSheet
|
||||
Widget _buildLoadingBottomSheet(ThemeController themeController) {
|
||||
Widget _buildLoadingBottomSheet(
|
||||
ThemeController themeController,
|
||||
Color pickerBackgroundColor,
|
||||
Color confirmTextColor,
|
||||
) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc17,
|
||||
color: pickerBackgroundColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20.rpx),
|
||||
topRight: Radius.circular(20.rpx),
|
||||
@@ -692,7 +730,7 @@ Widget _buildLoadingBottomSheet(ThemeController themeController) {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: themeController.currentColor.sc2,
|
||||
color: confirmTextColor,
|
||||
),
|
||||
SizedBox(height: 20.rpx),
|
||||
Text(
|
||||
@@ -709,11 +747,15 @@ Widget _buildLoadingBottomSheet(ThemeController themeController) {
|
||||
|
||||
// 错误 BottomSheet
|
||||
Widget _buildErrorBottomSheet(
|
||||
ThemeController themeController, BuildContext context) {
|
||||
ThemeController themeController,
|
||||
BuildContext context,
|
||||
Color pickerBackgroundColor,
|
||||
Color confirmTextColor,
|
||||
) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc17,
|
||||
color: pickerBackgroundColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20.rpx),
|
||||
topRight: Radius.circular(20.rpx),
|
||||
@@ -739,7 +781,7 @@ Widget _buildErrorBottomSheet(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 30.rpx, vertical: 15.rpx),
|
||||
decoration: BoxDecoration(
|
||||
color: themeController.currentColor.sc2,
|
||||
color: confirmTextColor,
|
||||
borderRadius: BorderRadius.circular(8.rpx),
|
||||
),
|
||||
child: Text(
|
||||
@@ -754,4 +796,4 @@ Widget _buildErrorBottomSheet(
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user