样式交互修改

This commit is contained in:
2026-01-06 17:57:56 +08:00
parent 6cc123f272
commit c57c849073
4 changed files with 131 additions and 76 deletions

View File

@@ -13,15 +13,12 @@ import 'reservation_list_bottomsheet.dart';
class ReservationPage extends GetView<C_ReservationController> {
ReservationPage({super.key});
@override
Widget build(BuildContext context) {
return GetBuilder<C_ReservationController>(
init: C_ReservationController(),
id: 'reservation',
builder: (_) {
return Scaffold(
backgroundColor: Colors.grey[100],
body: GestureDetector(
@@ -273,12 +270,12 @@ class ReservationPage extends GetView<C_ReservationController> {
hint: '当前最大可预约氢量${controller.difference}(KG)',
keyboardType: TextInputType.number,
),
_buildTextField(
/*_buildTextField(
label: '车牌号',
controller: controller.plateNumberController,
hint: '请输入车牌号', // 修改提示文案
enabled: false, // 设置为不可编辑
),
),*/
_buildStationSelector(),
const SizedBox(height: 20),
Row(
@@ -332,8 +329,6 @@ class ReservationPage extends GetView<C_ReservationController> {
);
}
// 表单中的可点击行 (用于日期和时间选择)
Widget _buildPickerRow({
required String label,
@@ -378,6 +373,7 @@ class ReservationPage extends GetView<C_ReservationController> {
TextInputType? keyboardType,
bool enabled = true,
}) {
bool showCounter = keyboardType == TextInputType.number;
return Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: Column(
@@ -401,6 +397,25 @@ class ReservationPage extends GetView<C_ReservationController> {
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
filled: !enabled,
fillColor: Colors.grey[100],
// 左侧减号按钮
prefixIcon: showCounter
? IconButton(
icon: const Icon(Icons.remove, color: Colors.blue),
onPressed: () => _updateAmount(-1),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(minWidth: 40, minHeight: 40),
)
: null,
// 右侧加号按钮
suffixIcon: showCounter
? IconButton(
icon: const Icon(Icons.add, color: Colors.blue),
onPressed: () => _updateAmount(1),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(minWidth: 40, minHeight: 40),
)
: null,
),
),
],
@@ -408,6 +423,37 @@ class ReservationPage extends GetView<C_ReservationController> {
);
}
// :更新氢量逻辑
void _updateAmount(int change) {
// 获取当前输入框的值,默认为 0
double currentAmount = double.tryParse(controller.amountController.text) ?? 0;
// 获取最大值,注意处理 difference 可能为空或非数字的情况
double maxAmount = double.tryParse(controller.difference.toString()) ?? 9999;
// 计算新值
double newAmount = currentAmount + change;
// 边界检查
if (newAmount < 1) {
newAmount = 1; // 最小不能小于 1
} else if (newAmount > maxAmount) {
newAmount = maxAmount; // 最大不能超过 difference
}
// 如果是整数,去掉小数点显示
if (newAmount == newAmount.toInt()) {
controller.amountController.text = newAmount.toInt().toString();
} else {
controller.amountController.text = newAmount.toStringAsFixed(2);
}
// 移动光标到末尾,防止光标跳到前面
controller.amountController.selection = TextSelection.fromPosition(
TextPosition(offset: controller.amountController.text.length),
);
}
Widget _buildStationSelector() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -428,7 +474,7 @@ class ReservationPage extends GetView<C_ReservationController> {
),
),
Obx(
() => DropdownButtonHideUnderline(
() => DropdownButtonHideUnderline(
child: DropdownButton2<String>(
isExpanded: true,
hint: const Text(
@@ -439,15 +485,15 @@ class ReservationPage extends GetView<C_ReservationController> {
items: controller.stationOptions
.map(
(station) => DropdownMenuItem<String>(
value: station.hydrogenId, // value 是站点的唯一ID
enabled: station.isSelect == 1,
child: _buildDropdownItem(station), // child 是自定义的 Widget
),
)
value: station.hydrogenId, // value 是站点的唯一ID
enabled: station.isSelect == 1,
child: _buildDropdownItem(station), // child 是自定义的 Widget
),
)
.toList(),
value:
// 当前的站点 处理默认
controller.selectedStationId.value ??
// 当前的站点 处理默认
controller.selectedStationId.value ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first.hydrogenId
: null),
@@ -460,15 +506,15 @@ class ReservationPage extends GetView<C_ReservationController> {
customButton: Obx(() {
// 优先从已选中的 ID 查找
var selectedStation = controller.stationOptions.firstWhereOrNull(
(s) => s.hydrogenId == controller.selectedStationId.value,
(s) => s.hydrogenId == controller.selectedStationId.value,
);
// 如果找不到已选中的(比如 ID 为空或列表里没有),并且列表不为空,则取第一个作为默认
final stationToShow =
selectedStation ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first
: null);
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first
: null);
// 如果有要显示的站点,就构建按钮
if (stationToShow != null) {