diff --git a/ln_jq_app/lib/pages/c_page/reservation/view.dart b/ln_jq_app/lib/pages/c_page/reservation/view.dart index bd67abc..1720f39 100644 --- a/ln_jq_app/lib/pages/c_page/reservation/view.dart +++ b/ln_jq_app/lib/pages/c_page/reservation/view.dart @@ -457,27 +457,37 @@ class ReservationPage extends GetView { /// 时间 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 { 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();