更新部分显示样式

This commit is contained in:
wyf
2025-12-09 15:47:05 +08:00
parent 5e63f2dfdc
commit e7c51bea52
15 changed files with 223 additions and 122 deletions

View File

@@ -56,66 +56,6 @@ getOnePicker(BuildContext context, List arr, int checkIndex,
);
}
// Widget getOnePickers(
// BuildContext context,
// List arr,
// RxInt selectedIndex, {
// String unit = '',
// bool looping = false,
// void Function(int)? onChanged,
// bool isMonthName = false,
// Key? pickerKey,
// }) {
// ThemeController themeController = Get.find();
// final bool isEn = Get.locale?.languageCode.startsWith('en') ?? false;
// return Obx(() {
// final dynamicKey = ValueKey('picker_${arr.length}_${selectedIndex.value}');
// return CupertinoPicker.builder(
// key: pickerKey ?? dynamicKey,
// itemExtent: 90.rpx,
// useMagnifier: false,
// magnification: 1,
// diameterRatio: 1.3,
// squeeze: 1,
// scrollController:
// FixedExtentScrollController(initialItem: selectedIndex.value),
// selectionOverlay: Container(),
// onSelectedItemChanged: (int index) {
// selectedIndex.value = index;
// if (onChanged != null) onChanged(index);
// },
// childCount: arr.length,
// itemBuilder: (context, index) {
// bool isSelected = index == selectedIndex.value;
// // 处理显示文本
// String displayText;
// if (isMonthName && isEn && arr[index] is int) {
// displayText = DateFormat.MMMM('en').format(DateTime(0, arr[index]));
// } else {
// // displayText = isEn ? "${arr[index]}" : "${arr[index]}$unit"; // 中文附带单位
// displayText = "${arr[index]}$unit"; // 中文附带单位
// }
// return Center(
// child: Text(
// displayText,
// style: TextStyle(
// fontFamily: 'Readex Pro',
// color: isSelected
// ? themeController.currentColor.sc3
// : const Color(0xFF9AA0B3),
// fontSize: 30.rpx,
// fontWeight: FontWeight.normal,
// ),
// ),
// );
// },
// );
// });
// }
Widget getOnePickers(
BuildContext context,
List arr,
@@ -125,6 +65,66 @@ Widget getOnePickers(
void Function(int)? onChanged,
bool isMonthName = false,
Key? pickerKey,
}) {
ThemeController themeController = Get.find();
final bool isEn = Get.locale?.languageCode.startsWith('en') ?? false;
return Obx(() {
final dynamicKey = ValueKey('picker_${arr.length}_${selectedIndex.value}');
return CupertinoPicker.builder(
key: pickerKey ?? dynamicKey,
itemExtent: 90.rpx,
useMagnifier: false,
magnification: 1,
diameterRatio: 1.3,
squeeze: 1,
scrollController:
FixedExtentScrollController(initialItem: selectedIndex.value),
selectionOverlay: Container(),
onSelectedItemChanged: (int index) {
selectedIndex.value = index;
if (onChanged != null) onChanged(index);
},
childCount: arr.length,
itemBuilder: (context, index) {
bool isSelected = index == selectedIndex.value;
// 处理显示文本
String displayText;
if (isMonthName && isEn && arr[index] is int) {
displayText = DateFormat.MMMM('en').format(DateTime(0, arr[index]));
} else {
// displayText = isEn ? "${arr[index]}" : "${arr[index]}$unit"; // 中文附带单位
displayText = "${arr[index]}$unit"; // 中文附带单位
}
return Center(
child: Text(
displayText,
style: TextStyle(
fontFamily: 'Readex Pro',
color: isSelected
? themeController.currentColor.sc3
: const Color(0xFF9AA0B3),
fontSize: 30.rpx,
fontWeight: FontWeight.normal,
),
),
);
},
);
});
}
Widget getOnePickersSpe(
BuildContext context,
List arr,
RxInt selectedIndex, {
String unit = '',
bool looping = false,
void Function(int)? onChanged,
bool isMonthName = false,
Key? pickerKey,
/// ⭐ 新增:可选的自定义显示,但不影响旧用法
String Function(dynamic value)? customDisplay,