加氢站默认选择,演示账号数据

附件默认显示,详情
This commit is contained in:
2025-12-16 11:58:00 +08:00
parent 4ace3c9f27
commit 9ce46a0c7d
9 changed files with 231 additions and 59 deletions

View File

@@ -437,20 +437,40 @@ class ReservationPage extends GetView<C_ReservationController> {
),
)
.toList(),
value: controller.selectedStationId.value,
value:
// 当前的站点 处理默认
controller.selectedStationId.value ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first.hydrogenId
: null),
// 当前选中的是站点ID
onChanged: (value) {
if (value != null) {
controller.selectedStationId.value = value;
}
},
customButton: controller.selectedStationId.value == null
? null // 未选择时,显示默认的 hint
: _buildSelectedStationButton(
controller.stationOptions.firstWhere(
(s) => s.hydrogenId == controller.selectedStationId.value,
),
),
customButton: Obx(() {
// 优先从已选中的 ID 查找
var selectedStation = controller.stationOptions.firstWhereOrNull(
(s) => s.hydrogenId == controller.selectedStationId.value,
);
// 如果找不到已选中的(比如 ID 为空或列表里没有),并且列表不为空,则取第一个作为默认
final stationToShow =
selectedStation ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first
: null);
// 如果有要显示的站点,就构建按钮
if (stationToShow != null) {
return _buildSelectedStationButton(stationToShow);
}
// 否则,返回一个空占位符,让 hint 生效
// DropdownButton2 内部会判断,如果 customButton 返回的不是一个有效Widget或根据其内部逻辑就会显示 hint
return const SizedBox.shrink();
}),
buttonStyleData: ButtonStyleData(
height: 40, // 增加高度以容纳两行文字
padding: const EdgeInsets.symmetric(horizontal: 12.0),