查看预约列表
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:getx_scaffold/common/index.dart';
|
||||
import 'package:getx_scaffold/common/widgets/text_x.dart';
|
||||
// import 'package:getx_scaffold/getx_scaffold.dart'; // 如果不使用其中的扩展,可以注释掉
|
||||
|
||||
import 'controller.dart';
|
||||
@@ -76,10 +79,17 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
children: [
|
||||
Icon(Icons.shield_outlined, color: Colors.blue, size: 14),
|
||||
SizedBox(width: 4),
|
||||
Text('已认证', style: TextStyle(color: Colors.blue, fontSize: 10, fontWeight: FontWeight.bold)),
|
||||
Text(
|
||||
'已认证',
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -88,10 +98,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildStatItem('0Kg', '累计加氢'),
|
||||
_buildStatItem('0次', '加氢次数'),
|
||||
],
|
||||
children: [_buildStatItem('0Kg', '累计加氢'), _buildStatItem('0次', '加氢次数')],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -131,7 +138,11 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Icon(Icons.propane_tank_outlined, size: 80, color: Colors.blue.withOpacity(0.5)),
|
||||
Icon(
|
||||
Icons.propane_tank_outlined,
|
||||
size: 80,
|
||||
color: Colors.blue.withOpacity(0.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -147,15 +158,20 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
const SizedBox(width: 8),
|
||||
isButton
|
||||
? ElevatedButton.icon(
|
||||
onPressed: () { /* TODO: 扫码绑定逻辑 */ },
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 16),
|
||||
label: Text(value),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
),
|
||||
)
|
||||
: Text(value, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
onPressed: () {
|
||||
/* TODO: 扫码绑定逻辑 */
|
||||
},
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 16),
|
||||
label: Text(value),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
value,
|
||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -168,47 +184,97 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
// 【修改】使用 Obx 包裹以自动响应 Rx 变量的变化
|
||||
child: Obx(() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildPickerRow(
|
||||
label: '日期',
|
||||
value: controller.formattedDate,
|
||||
icon: Icons.calendar_today_outlined,
|
||||
onTap: () => controller.pickDate(context),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '开始时间',
|
||||
value: controller.formattedStartTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, true),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '结束时间',
|
||||
value: controller.formattedEndTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, false),
|
||||
),
|
||||
_buildTextField(label: '预约氢量(kg)', controller: controller.amountController, hint: '请输入氢量(kg)', keyboardType: TextInputType.number),
|
||||
_buildTextField(label: '车牌号', controller: controller.plateNumberController, hint: '请输入车牌号'),
|
||||
_buildStationSelector(),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: controller.submitReservation,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
child: Obx(
|
||||
() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildPickerRow(
|
||||
label: '日期',
|
||||
value: controller.formattedDate,
|
||||
icon: Icons.calendar_today_outlined,
|
||||
onTap: () => controller.pickDate(context),
|
||||
),
|
||||
child: const Text('提交预约', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
)),
|
||||
_buildPickerRow(
|
||||
label: '开始时间',
|
||||
value: controller.formattedStartTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, true),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '结束时间',
|
||||
value: controller.formattedEndTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, false),
|
||||
),
|
||||
_buildTextField(
|
||||
label: '预约氢量(kg)',
|
||||
controller: controller.amountController,
|
||||
hint: '请输入氢量(kg)',
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
_buildTextField(
|
||||
label: '车牌号',
|
||||
controller: controller.plateNumberController,
|
||||
hint: '请输入车牌号',
|
||||
),
|
||||
_buildStationSelector(),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: controller.submitReservation,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
backgroundColor: Colors.blue, // 明确指定背景色
|
||||
foregroundColor: Colors.white, // 明确指定前景色(文字颜色)
|
||||
),
|
||||
child: const Text(
|
||||
'提交预约',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: controller.getReservationList,
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48), // 高度与另一个按钮保持一致
|
||||
side: const BorderSide(color: Colors.blue), // 设置边框颜色为蓝色
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'查看预约', // 假设第二个按钮是“取消”
|
||||
style: TextStyle(
|
||||
color: Colors.blue, // 设置文字颜色为蓝色
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 表单中的可点击行 (用于日期和时间选择)
|
||||
Widget _buildPickerRow({required String label, required String value, required IconData icon, required VoidCallback onTap}) {
|
||||
Widget _buildPickerRow({
|
||||
required String label,
|
||||
required String value,
|
||||
required IconData icon,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: Column(
|
||||
@@ -239,7 +305,12 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
}
|
||||
|
||||
// 表单中的文本输入框
|
||||
Widget _buildTextField({required String label, required TextEditingController controller, required String hint, TextInputType? keyboardType}) {
|
||||
Widget _buildTextField({
|
||||
required String label,
|
||||
required TextEditingController controller,
|
||||
required String hint,
|
||||
TextInputType? keyboardType,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: Column(
|
||||
@@ -261,7 +332,6 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
);
|
||||
}
|
||||
|
||||
// 构建加氢站选择器
|
||||
Widget _buildStationSelector() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
@@ -272,59 +342,109 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('加氢站', style: TextStyle(color: Colors.grey[600], fontSize: 14)),
|
||||
TextButton(onPressed: () { /* TODO: 刷新站点列表 */ }, child: const Text('刷新')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showToast("msg");
|
||||
},
|
||||
child: const Text('刷新'),
|
||||
),
|
||||
],
|
||||
),
|
||||
// 【修改】使用 Obx 包裹 DropdownButtonFormField 以响应 Rx 变量
|
||||
Obx(() => DropdownButtonFormField<String>(
|
||||
value: controller.selectedStation.value,
|
||||
isExpanded: true,
|
||||
items: controller.stationOptions.map((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(width: 8),
|
||||
if (value.contains('银河路')) // 示例:给特定站点加标签
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text('维修中', style: TextStyle(color: Colors.orange, fontSize: 10)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Text(
|
||||
'江苏省苏州市常熟市东南街道银河路80号 | ¥45.00/kg',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
Obx(
|
||||
() => DropdownButtonHideUnderline(
|
||||
child: DropdownButton2<String>(
|
||||
isExpanded: true,
|
||||
hint: Text(
|
||||
'请选择加氢站',
|
||||
style: TextStyle(fontSize: 14, color: Theme.of(Get.context!).hintColor),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (newValue) {
|
||||
if (newValue != null) {
|
||||
controller.selectedStation.value = newValue;
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||
items: controller.stationOptions
|
||||
.map(
|
||||
(item) => DropdownMenuItem(
|
||||
value: item,
|
||||
child: _buildDropdownItem(item), // 使用自定义 Widget 构建 Item
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: controller.selectedStation.value,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
controller.selectedStation.value = value;
|
||||
}
|
||||
},
|
||||
buttonStyleData: ButtonStyleData(
|
||||
height: 55, // 控制按钮的高度
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0), // 控制按钮内部的内边距
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey[400]!),
|
||||
),
|
||||
),
|
||||
iconStyleData: const IconStyleData(
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
),
|
||||
dropdownStyleData: DropdownStyleData(
|
||||
maxHeight: 200,
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(8)),
|
||||
offset: const Offset(0, -5),
|
||||
elevation: 8,
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(
|
||||
height: 55, // 控制每个下拉选项的高度
|
||||
padding: EdgeInsets.symmetric(horizontal: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///用于构建 DropdownMenuItem 内部的自定义 Widget
|
||||
Widget _buildDropdownItem(String value) {
|
||||
bool isSpecial = value.contains('银河路');
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (isSpecial) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'维修中',
|
||||
style: TextStyle(color: Colors.orange, fontSize: 10),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
const Text(
|
||||
'江苏省苏州市常熟市东南街道银河路80号 | ¥45.00/kg',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 11),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建提示信息卡片
|
||||
Widget _buildTipsCard() {
|
||||
return Card(
|
||||
@@ -351,7 +471,9 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
children: [
|
||||
Icon(icon, color: Colors.blue, size: 20),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(text, style: const TextStyle(fontSize: 12, color: Colors.black54))),
|
||||
Expanded(
|
||||
child: Text(text, style: const TextStyle(fontSize: 12, color: Colors.black54)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user