扫码结果处理
This commit is contained in:
@@ -421,7 +421,7 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
|
||||
var responseData = await HttpService.to.get("hydrogen/queryHydrogenSiteInfo");
|
||||
|
||||
if (responseData == null && responseData!.data == null) {
|
||||
if (responseData == null || responseData.data == null) {
|
||||
showToast('暂时无法获取站点信息');
|
||||
dismissLoading();
|
||||
return;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:getx_scaffold/getx_scaffold.dart';
|
||||
import 'package:ln_jq_app/common/model/vehicle_info.dart';
|
||||
import 'package:ln_jq_app/pages/qr_code/view.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
@@ -116,7 +117,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
children: [
|
||||
Text(value, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 11 )),
|
||||
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 11)),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -142,11 +143,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.propane_rounded,
|
||||
size: 50,
|
||||
color: Colors.blue.withOpacity(0.5),
|
||||
),
|
||||
Icon(Icons.propane_rounded, size: 50, color: Colors.blue.withOpacity(0.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -162,8 +159,18 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
const SizedBox(width: 8),
|
||||
isButton
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
Get.to(() => const QrCodePage());
|
||||
onTap: () async {
|
||||
//判断是否绑定成功
|
||||
var scanResult = await Get.to(() => const QrCodePage());
|
||||
if (scanResult == true) {
|
||||
VehicleInfo? bean = StorageService.to.vehicleInfo;
|
||||
|
||||
if (bean != null) {
|
||||
showToast(
|
||||
"已绑定${bean.plateNumber}-${StorageService.to.hasVehicleInfo}",
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsetsGeometry.only(left: 10.w),
|
||||
@@ -181,7 +188,10 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
color: Colors.blue, fontSize: 11, fontWeight: FontWeight.w500),
|
||||
color: Colors.blue,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -411,13 +421,9 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
),
|
||||
dropdownStyleData: DropdownStyleData(
|
||||
maxHeight: 200,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(
|
||||
height: 40,
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(height: 40),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -6,6 +6,9 @@ import 'package:get/get.dart';
|
||||
import 'package:getx_scaffold/getx_scaffold.dart';
|
||||
import 'package:image/image.dart' as img;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:ln_jq_app/common/model/base_model.dart';
|
||||
import 'package:ln_jq_app/common/model/vehicle_info.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart';
|
||||
import 'package:qr_code_scanner_plus/qr_code_scanner_plus.dart';
|
||||
import 'package:zxing_lib/common.dart';
|
||||
import 'package:zxing_lib/qrcode.dart';
|
||||
@@ -134,28 +137,43 @@ class QrCodeController extends GetxController
|
||||
showErrorToast('相机权限未被授予,请到权限管理中打开');
|
||||
}
|
||||
if (!isPhotosGranted) {
|
||||
showErrorToast(
|
||||
'相册权限未被授予,请到权限管理中打开',
|
||||
);
|
||||
showErrorToast('相册权限未被授予,请到权限管理中打开');
|
||||
}
|
||||
}
|
||||
|
||||
//扫码结果处理
|
||||
void renderResult(String resultStr) {
|
||||
Get.defaultDialog(
|
||||
title: "扫描结果",
|
||||
middleText: resultStr,
|
||||
onConfirm: () {
|
||||
Get.back();
|
||||
resumeScanner();
|
||||
},
|
||||
onCancel: () {
|
||||
resumeScanner();
|
||||
},
|
||||
);
|
||||
void renderResult(String resultStr) async {
|
||||
showLoading("正在获取车辆信息...");
|
||||
try {
|
||||
var responseData = await HttpService.to.get(
|
||||
"appointment/truck/base-info?vin=$resultStr",
|
||||
);
|
||||
|
||||
if (responseData == null || responseData.data == null) {
|
||||
showToast('无法获取车辆信息,请检查网络或稍后重试');
|
||||
resumeScanner();
|
||||
return;
|
||||
}
|
||||
|
||||
var result = BaseModel.fromJson(responseData.data);
|
||||
final vehicle = VehicleInfo.fromJson(result.data as Map<String, dynamic>);
|
||||
//保存使用
|
||||
await StorageService.to.saveVehicleInfo(vehicle);
|
||||
|
||||
Get.back(result: true);
|
||||
|
||||
} on DioException catch (e) {
|
||||
showErrorToast("网络请求失败,请稍后重试");
|
||||
resumeScanner();
|
||||
} catch (e, stackTrace) {
|
||||
showErrorToast("处理失败,请稍后重试");
|
||||
resumeScanner(); // 未知异常,恢复扫描
|
||||
} finally {
|
||||
dismissLoading();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
qrViewController?.dispose();
|
||||
|
||||
Reference in New Issue
Block a user