进度条

This commit is contained in:
2026-02-12 17:34:06 +08:00
parent 3dfc1dfc2c
commit 600cea4379

View File

@@ -457,27 +457,37 @@ class ReservationPage extends GetView<C_ReservationController> {
/// 时间 Slider 选择器
Widget _buildTimeSlider(BuildContext context) {
return Obx(() {
// 获取当前小时作为滑块值 (0-23)
int currentHour = controller.startTime.value.hour;
// 动态获取站点的营业范围限制
// 1. 获取站点信息
final station = controller.stationOptions.firstWhereOrNull(
(s) => s.hydrogenId == controller.selectedStationId.value,
(s) => s.hydrogenId == controller.selectedStationId.value,
);
// 解析营业时间
// 处理格式如 "09:00" 或 "09:00:00"
final startParts = (station?.startBusiness ?? "00:00").split(':');
final endParts = (station?.endBusiness ?? "23:59").split(':');
// 如果没有站点数据,说明正在加载或未选择,直接不显示进度条,避免范围跳变产生的滑动
if (station == null) {
return const SizedBox(height: 100);
}
// 2. 解析营业范围
final startParts = station.startBusiness.split(':');
final endParts = station.endBusiness.split(':');
int bizStartHour = int.tryParse(startParts[0]) ?? 0;
int bizEndHour = int.tryParse(endParts[0]) ?? 23;
int bizEndMinute = (endParts.length > 1) ? (int.tryParse(endParts[1]) ?? 0) : 0;
if (bizEndMinute == 0 && bizEndHour > bizStartHour) bizEndHour--;
// 3. 确定当前滑块值
int currentHour = controller.startTime.value.hour;
double sliderValue = currentHour.toDouble().clamp(
bizStartHour.toDouble(),
bizEndHour.toDouble()
);
double minVal = bizStartHour.toDouble();
double maxVal = bizEndHour.toDouble();
if (minVal >= maxVal) maxVal = minVal + 1;
// 优化结束小时逻辑
// 如果分钟为 0 (例如 18:00),说明该小时整点已关门,最大可选小时应减 1
if (bizEndMinute == 0 && bizEndHour > 0) {
bizEndHour--;
}
return Column(
children: [
@@ -526,12 +536,9 @@ class ReservationPage extends GetView<C_ReservationController> {
overlayColor: const Color(0xFF006633).withOpacity(0.1),
),
child: Slider(
value: currentHour.toDouble().clamp(
bizStartHour.toDouble(),
bizEndHour.toDouble(),
),
min: bizStartHour.toDouble(),
max: bizEndHour.toDouble(),
value: sliderValue,
min: minVal,
max: maxVal,
// divisions: bizEndHour - bizStartHour > 0 ? bizEndHour - bizStartHour : 1,
onChanged: (val) {
int hour = val.toInt();