查询数据
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
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 'package:getx_scaffold/getx_scaffold.dart';
|
||||
|
||||
import '../../../storage_service.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class ReservationPage extends GetView<ReservationController> {
|
||||
@@ -12,33 +11,35 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 【修改】使用 Get.put 来初始化 Controller,而不是在 GetBuilder 中。这是更推荐的做法。
|
||||
// Get.lazyPut 会在第一次使用时才创建实例。
|
||||
Get.lazyPut(() => ReservationController());
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildUserInfoCard(),
|
||||
const SizedBox(height: 12),
|
||||
_buildCarInfoCard(),
|
||||
const SizedBox(height: 12),
|
||||
_buildReservationFormCard(context), // 将 context 传入
|
||||
const SizedBox(height: 12),
|
||||
_buildTipsCard(),
|
||||
],
|
||||
),
|
||||
),
|
||||
return GetBuilder<ReservationController>(
|
||||
init: ReservationController(),
|
||||
id: 'reservation',
|
||||
builder: (_) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey[100],
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildUserInfoCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildCarInfoCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildReservationFormCard(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建顶部用户信息卡片
|
||||
/// 构建用户信息卡片
|
||||
Widget _buildUserInfoCard() {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
elevation: 2, // 轻微的阴影
|
||||
shadowColor: Colors.black.withOpacity(0.1),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -52,17 +53,17 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
child: Icon(Icons.person, color: Colors.white, size: 30),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'王小龙',
|
||||
controller.name,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'15888332828',
|
||||
controller.phone,
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
],
|
||||
@@ -98,7 +99,10 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [_buildStatItem('0Kg', '累计加氢'), _buildStatItem('0次', '加氢次数')],
|
||||
children: [
|
||||
_buildStatItem(controller.fillingWeight, '累计加氢'),
|
||||
_buildStatItem(controller.fillingTimes, '加氢次数'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -129,11 +133,11 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow('车牌号:', '扫码绑定'),
|
||||
_buildInfoRow('车牌号: ${controller.plateNumber}', '扫码绑定'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('剩余氢量:', '0Kg'),
|
||||
_buildInfoRow('剩余氢量:', '${controller.leftHydrogen}Kg'),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow('百公里氢耗:', '0KG/100KM'),
|
||||
_buildInfoRow('百公里氢耗:', '${controller.workEfficiency}KG/100KM'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -215,7 +219,8 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
_buildTextField(
|
||||
label: '车牌号',
|
||||
controller: controller.plateNumberController,
|
||||
hint: '请输入车牌号',
|
||||
hint: '请输入车牌号', // 修改提示文案
|
||||
enabled: false, // 设置为不可编辑
|
||||
),
|
||||
_buildStationSelector(),
|
||||
const SizedBox(height: 24),
|
||||
@@ -310,6 +315,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
required TextEditingController controller,
|
||||
required String hint,
|
||||
TextInputType? keyboardType,
|
||||
bool enabled = true,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
@@ -321,10 +327,14 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
enabled: enabled, // 使用 enabled 参数
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
// 【新增】禁用时,使用填充色
|
||||
filled: !enabled,
|
||||
fillColor: Colors.grey[100],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -344,7 +354,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
Text('加氢站', style: TextStyle(color: Colors.grey[600], fontSize: 14)),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showToast("msg");
|
||||
controller.getSiteList();
|
||||
},
|
||||
child: const Text('刷新'),
|
||||
),
|
||||
@@ -382,18 +392,13 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
),
|
||||
iconStyleData: const IconStyleData(
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
iconSize: 20,
|
||||
),
|
||||
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),
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(height: 40),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -402,78 +407,12 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
);
|
||||
}
|
||||
|
||||
///用于构建 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(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildTipItem(Icons.info_outline, '请提前30分钟到达加氢站'),
|
||||
const SizedBox(height: 10),
|
||||
_buildTipItem(Icons.rule, '请确保车辆证件齐全'),
|
||||
const SizedBox(height: 10),
|
||||
_buildTipItem(Icons.headset_mic_outlined, '如有疑问请联系客服: 400-123-4567'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 提示信息卡片中的列表项
|
||||
Widget _buildTipItem(IconData icon, String text) {
|
||||
Widget _buildDropdownItem(String item) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, color: Colors.blue, size: 20),
|
||||
const Icon(Icons.local_gas_station_outlined, size: 18, color: Colors.grey),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(text, style: const TextStyle(fontSize: 12, color: Colors.black54)),
|
||||
),
|
||||
Text(item, style: const TextStyle(fontSize: 14)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user