瀏覽代碼

移除冗余代码

gavin.chen 1 年之前
父節點
當前提交
df8dceca6f

+ 0 - 444
lib/pages/id_card_scan/controller.dart

@@ -1,5 +1,4 @@
 import 'dart:async';
-import 'dart:convert';
 import 'package:camera/camera.dart';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:flutter/foundation.dart';
@@ -7,23 +6,19 @@ import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:get/get.dart';
 import 'package:google_mlkit_face_detection/google_mlkit_face_detection.dart';
-import 'package:image_gallery_saver/image_gallery_saver.dart';
 import 'package:vitalapp/architecture/storage/storage.dart';
-import 'package:vitalapp/architecture/utils/datetime.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
 import 'package:vitalapp/managers/interfaces/cache.dart';
 import 'package:fis_common/logger/logger.dart';
 import 'package:vitalapp/managers/interfaces/patient.dart';
 import 'package:vitalapp/rpc.dart';
 import 'package:vitalapp/store/store.dart';
-import 'dart:ui' as ui;
 import 'index.dart';
 
 class IdCardScanController extends GetxController with WidgetsBindingObserver {
   IdCardScanController();
 
   final state = IdCardScanState();
-  final _patientManager = Get.find<IPatientManager>();
   List<CameraDescription> _cameras = <CameraDescription>[];
   List<CameraDescription> get cameras => _cameras;
 
@@ -38,9 +33,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
   // 屏幕上手指数量
   int pointers = 0;
 
-  // 当前身份证信息
-  IdCardInfoModel idCardInfo = IdCardInfoModel();
-
   /// 开始缩放
   void handleScaleStart(ScaleStartDetails details) {
     _baseScale = _currentScale;
@@ -252,91 +244,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
     }
   }
 
-  /// 测试图像文件缓存,print 遍历输出
-  void debugShowCache() async {
-    final cacheManager = Get.find<ICacheManager>();
-    double cacheSize = await cacheManager.getCacheSize();
-    double imageCacheSize = await cacheManager.getImageCacheSize();
-    debugPrint('cacheSize = $cacheSize : ${formatSize(cacheSize)}');
-    debugPrint(
-        'imageCacheSize = $imageCacheSize : ${formatSize(imageCacheSize)}');
-  }
-
-  /// 文件大小转为可读 Str
-  static String formatSize(double value) {
-    List<String> unitArr = ['B', 'K', 'M', 'G'];
-    int index = 0;
-    while (value > 1024) {
-      index++;
-      value = value / 1024;
-    }
-    String size = value.toStringAsFixed(2);
-    return size + unitArr[index];
-  }
-
-  /// 保存到相册
-  void saveImageToGallery(XFile image) async {
-    // 获取图像的字节数据
-    Uint8List bytes = await image.readAsBytes();
-
-    // 将图像保存到相册
-    await ImageGallerySaver.saveImage(bytes, quality: 100);
-  }
-
-  /// 处理图像裁切
-  Future<String> clipLocalImage(XFile soureceImage, double scale) async {
-    assert(scale >= 1, 'scale must be greater than 1');
-    // 获取图像的字节数据
-    Uint8List bytes = await soureceImage.readAsBytes();
-    var codec = await ui.instantiateImageCodec(bytes);
-    var nextFrame = await codec.getNextFrame();
-    var image = nextFrame.image;
-    Rect src = Rect.fromLTWH(
-      (scale - 1) / 2 / scale * image.width.toDouble(),
-      (scale - 1) / 2 / scale * image.height.toDouble(),
-      image.width.toDouble() / scale,
-      image.height.toDouble() / scale,
-    );
-    Rect dst =
-        Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble());
-    ui.Image croppedImage = await getCroppedImage(image, src, dst);
-    ByteData? newImageBytes =
-        await croppedImage.toByteData(format: ui.ImageByteFormat.png);
-    if (newImageBytes == null) {
-      return '';
-    }
-    Uint8List newImageUint8List = newImageBytes.buffer.asUint8List();
-
-    /// FIXME 不要存到相册而是存到临时目录
-    Map<Object?, Object?> result =
-        await ImageGallerySaver.saveImage(newImageUint8List, quality: 100);
-    String jsonString = jsonEncode(result);
-    Map<String, dynamic> json = jsonDecode(jsonString);
-    String? filePath = json['filePath'];
-    return filePath ?? '';
-  }
-
-  /// 获取图像文件的图像尺寸
-  Future<Size> getImageSize(XFile soureceImage) async {
-    // 获取图像的字节数据
-    Uint8List bytes = await soureceImage.readAsBytes();
-    var codec = await ui.instantiateImageCodec(bytes);
-    var nextFrame = await codec.getNextFrame();
-    var image = nextFrame.image;
-    return Size(image.width.toDouble(), image.height.toDouble());
-  }
-
-  /// 获取裁切后的图像
-  Future<ui.Image> getCroppedImage(ui.Image image, Rect src, Rect dst) {
-    var pictureRecorder = ui.PictureRecorder();
-    Canvas canvas = Canvas(pictureRecorder);
-    canvas.drawImageRect(image, src, dst, Paint());
-    return pictureRecorder.endRecording().toImage(
-          dst.width.floor(),
-          dst.height.floor(),
-        );
-  }
-
   /// 发生拍摄身份证事件
   void onCaptureIdCardButtonPressed() {
     state.isIdCardScanning = true;
@@ -344,7 +251,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
       // imageFile = file;
       if (file != null) {
         try {
-          // await clipLocalImage(file, 1.8);
           final url = await rpc.storage.upload(
             file,
             fileType: 'png',
@@ -357,7 +263,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
           );
           if (result.isSuccess) {
             PromptBox.toast('身份证识别成功');
-            idCardInfo.localCardImagePath = file.path;
             final idCardScanResult = IdCardScanResult(
               success: true,
               patientBaseDTO: result,
@@ -377,183 +282,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
     });
   }
 
-  /// 发生人脸录入事件
-  // void onCaptureFaceButtonPressed() async {
-  //   state.isRunningFaceInput = true;
-  //   if (kCameraController == null) {
-  //     state.isRunningFaceInput = false;
-  //     return;
-  //   }
-  //   try {
-  //     final XFile? file = await takePicture();
-  //     if (file != null) {
-  //       faceDetector = FaceDetector(options: FaceDetectorOptions());
-  //       // faceDetector =
-  //       //     FaceDetector(options: FaceDetectorOptions(enableContours: true));
-  //       int faceNum = 1; // max 分辨率下检测用时大约 100ms
-  //       // int faceNum =
-  //       //     await doDetection(faceDetector, file.path); // max 分辨率下检测用时大约 100ms
-
-  //       if (faceNum == 0) {
-  //         PromptBox.toast('请将面部保持在识别框内');
-  //         return;
-  //       } else if (faceNum > 1) {
-  //         PromptBox.toast('请保持只有一张面部在识别范围内');
-  //         return;
-  //       }
-
-  //       /// TODO 上传图像到云然后传给后端
-  //       final url = await rpc.storage.upload(
-  //         file,
-  //         fileType: 'png',
-  //       );
-  //       print('⭐⭐⭐⭐⭐⭐⭐⭐ url: $url');
-  //       try {
-  //         SavePersonDTO result =
-  //             await rpc.patient.savePatientBaseByFaceImageAsync(
-  //           SavePatientBaseByFaceImageRequest(
-  //             cardNo: idCardInfo.idCardNumber,
-  //             token: Store.user.token,
-  //             image: url,
-  //           ),
-  //         );
-  //         print(result);
-  //         if (result.success) {
-  //           PromptBox.toast('人脸数据存入成功');
-  //           final idCardScanResult = IdCardScanResult(
-  //             success: true,
-  //             cardNo: idCardInfo.idCardNumber,
-  //             name: idCardInfo.idCardName,
-  //             nation: idCardInfo.idCardNation,
-  //             gender: idCardInfo.idCardGender == '男'
-  //                 ? GenderEnum.Male
-  //                 : GenderEnum.Female,
-  //             birthday: DateTime.parse(idCardInfo.idCardBirthDate),
-  //             address: idCardInfo.idCardAddress,
-  //           );
-
-  //           Get.back<IdCardScanResult>(
-  //             result: idCardScanResult,
-  //           );
-  //         } else {
-  //           PromptBox.toast('人脸数据存入失败');
-  //         }
-  //       } catch (e) {
-  //         logger.e("savePatientBaseByFaceImageAsync failed: $e", e);
-  //       }
-  //     }
-  //   } catch (e) {
-  //     logger.e("doDetection failed: $e", e);
-  //   }
-  //   state.isRunningFaceInput = false;
-  // }
-
-  /// 发生结束录制视频事件
-  void onStopButtonPressed() {
-    stopVideoRecording().then((XFile? file) {
-      if (file != null) {
-        PromptBox.toast('Video recorded to ${file.path}');
-        // videoFile = file;
-        // _startVideoPlayer();
-      }
-      update();
-    });
-  }
-
-  /// 发生开始录制视频事件
-  void onVideoRecordButtonPressed() {
-    startVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 暂停录制视频
-  void onPauseButtonPressed() {
-    pauseVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 恢复视频录制
-  void onResumeButtonPressed() {
-    resumeVideoRecording().then((_) {
-      update();
-    });
-  }
-
-  /// 开始录制视频
-  Future<void> startVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isInitialized) {
-      PromptBox.toast('Error: select a camera first.');
-      return;
-    }
-
-    if (cameraController.value.isRecordingVideo) {
-      // A recording is already started, do nothing.
-      return;
-    }
-
-    try {
-      await cameraController.startVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-      return;
-    }
-  }
-
-  /// 停止录制视频
-  Future<XFile?> stopVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return null;
-    }
-
-    try {
-      return cameraController.stopVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      return null;
-    }
-  }
-
-  /// 暂停录制视频
-  Future<void> pauseVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return;
-    }
-
-    try {
-      await cameraController.pauseVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      rethrow;
-    }
-  }
-
-  /// 恢复视频录制
-  Future<void> resumeVideoRecording() async {
-    final CameraController? cameraController = kCameraController;
-
-    if (cameraController == null || !cameraController.value.isRecordingVideo) {
-      return;
-    }
-
-    try {
-      await cameraController.resumeVideoRecording();
-    } on CameraException catch (e) {
-      PromptBox.toast('Error: ${e.code}\n${e.description}');
-
-      rethrow;
-    }
-  }
-
   /// 在 widget 内存中分配后立即调用。
   @override
   void onInit() async {
@@ -576,7 +304,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
     super.onClose();
     final cacheManager = Get.find<ICacheManager>();
     cacheManager.clearApplicationImageCache();
-    closeDetector();
     WidgetsBinding.instance.removeObserver(this);
     final CameraController? cameraController = kCameraController;
     if (cameraController != null) {
@@ -609,177 +336,6 @@ class IdCardScanController extends GetxController with WidgetsBindingObserver {
       this.state.isCameraReady = true;
     }
   }
-
-  /// 完成人脸识别
-  void finishFaceDetection() {
-    // final result = IdCardScanResult(
-    //   success: true,
-    //   cardNo: idCardInfo.idCardNumber,
-    //   name: idCardInfo.idCardName,
-    //   nation: idCardInfo.idCardNation,
-    //   gender:
-    //       idCardInfo.idCardGender == '男' ? GenderEnum.Male : GenderEnum.Female,
-    //   birthday: DateTime.now(),
-    //   address: idCardInfo.idCardAddress,
-    // );
-
-    // Get.back<IdCardScanResult>(
-    //   result: result,
-    // );
-  }
-
-  /// WIP
-  /// 面部识别 基于 Google's ML Kit
-  ///
-
-  InputImage inputImage = InputImage.fromFilePath('');
-  FaceDetector faceDetector = FaceDetector(options: FaceDetectorOptions());
-
-  // 进行一次人脸检测
-  Future<void> doDetection(
-    FaceDetector faceDetector,
-    String imagePath,
-  ) async {
-    inputImage = InputImage.fromFilePath(imagePath);
-    // inputImage = image;
-    final List<Face> faces = await faceDetector.processImage(inputImage);
-    kFrameFacesResult = [];
-    kFrameFacesResult.addAll(faces);
-    // for (Face face in faces) {
-    //   final Rect boundingBox = face.boundingBox;
-
-    //   final double? rotX =
-    //       face.headEulerAngleX; // Head is tilted up and down rotX degrees
-    //   final double? rotY =
-    //       face.headEulerAngleY; // Head is rotated to the right rotY degrees
-    //   final double? rotZ =
-    //       face.headEulerAngleZ; // Head is tilted sideways rotZ degrees
-
-    //   // If landmark detection was enabled with FaceDetectorOptions (mouth, ears,
-    //   // eyes, cheeks, and nose available):
-    //   final FaceLandmark? leftEar = face.landmarks[FaceLandmarkType.leftEar];
-    //   if (leftEar != null) {
-    //     final Point<int> leftEarPos = leftEar.position;
-    //   }
-
-    //   // If classification was enabled with FaceDetectorOptions:
-    //   if (face.smilingProbability != null) {
-    //     final double? smileProb = face.smilingProbability;
-    //   }
-
-    //   // If face tracking was enabled with FaceDetectorOptions:
-    //   if (face.trackingId != null) {
-    //     final int? id = face.trackingId;
-    //   }
-    // }
-  }
-
-  // bool isDetectionRunning = false;
-  Timer? _detectionTimer;
-
-  /// 开始持续检测人脸
-  void runDetectionTimer() {
-    if (_detectionTimer != null) {
-      _detectionTimer!.cancel();
-      _detectionTimer = null;
-      faceDetector.close();
-      state.isShowIdCardScanResult = false;
-      return;
-    }
-    faceDetector =
-        FaceDetector(options: FaceDetectorOptions(enableContours: true));
-    state.isShowIdCardScanResult = true;
-
-    /// 记录最后一次拍摄的时间
-    int lastCaptureTime = DateTime.now().millisecondsSinceEpoch;
-    _detectionTimer = Timer.periodic(
-      const Duration(milliseconds: 300), // max 分辨率下拍摄用时大约 500ms-800ms
-      (timer) async {
-        if (kCameraController == null) {
-          return;
-        }
-        final XFile? file = await takePicture();
-        if (file != null) {
-          if (timer.tick == 1 || kFrameImageSize == Size.zero) {
-            Size imageSize = await getImageSize(file);
-            kFrameImageSize = imageSize;
-          }
-          int kTime = DateTime.now().millisecondsSinceEpoch;
-          print('⭐⭐⭐⭐⭐⭐⭐⭐ capture time: ${kTime - lastCaptureTime} ms');
-          lastCaptureTime = kTime;
-
-          /// 记录用时 ms
-          await doDetection(faceDetector, file.path); // max 分辨率下检测用时大约 100ms
-          int endTime = DateTime.now().millisecondsSinceEpoch;
-          print('⭐⭐⭐⭐⭐⭐⭐⭐ detection time: ${endTime - lastCaptureTime} ms');
-          update(['face_bounding_box']);
-          if (timer.tick >= 10) {
-            finishFaceDetection(); // TODO 接入真实的判断条件
-          }
-        }
-      },
-    );
-  }
-
-  /// 用于将读取的视频流传给 Google ML
-  InputImage cameraImageToInputImage(CameraImage cameraImage) {
-    return InputImage.fromBytes(
-      bytes: _concatenatePlanes(cameraImage.planes),
-      metadata: InputImageMetadata(
-        size: Size(cameraImage.width.toDouble(), cameraImage.height.toDouble()),
-        rotation: InputImageRotation.rotation0deg,
-        format: _getInputImageFormat(cameraImage.format.group),
-        bytesPerRow: cameraImage.planes[0].bytesPerRow,
-      ),
-    );
-  }
-
-  /// 辅助函数,将CameraImage的plane组合为Uint8List格式
-  Uint8List _concatenatePlanes(List<Plane> planes) {
-    final WriteBuffer allBytes = WriteBuffer();
-    for (Plane plane in planes) {
-      allBytes.putUint8List(plane.bytes);
-    }
-    return allBytes.done().buffer.asUint8List();
-  }
-
-  InputImageFormat _getInputImageFormat(ImageFormatGroup format) {
-    switch (format) {
-      case ImageFormatGroup.yuv420:
-        return InputImageFormat.yuv420;
-      case ImageFormatGroup.bgra8888:
-        return InputImageFormat.bgra8888;
-      default:
-        throw ArgumentError('Invalid image format');
-    }
-  }
-
-  /// 销毁检测器
-  void closeDetector() {
-    if (_detectionTimer != null) {
-      state.isShowIdCardScanResult = false;
-      _detectionTimer!.cancel();
-      _detectionTimer = null;
-    }
-    faceDetector.close();
-  }
-
-  Future<void> _createPatient(PatientBaseDTO result) async {
-    var createPatientRequest = CreatePatientRequest(
-      cardNo: idCardInfo.idCardNumber,
-      patientName: idCardInfo.idCardName,
-      phone: '',
-      patientGender:
-          idCardInfo.idCardGender == "男" ? GenderEnum.Male : GenderEnum.Female,
-      nationality: idCardInfo.idCardNation,
-      birthday: result.birthday!.toUtc(),
-      cardType: CardTypeEnum.Identity,
-      patientAddress: idCardInfo.idCardAddress,
-      permanentResidenceAddress: idCardInfo.idCardAddress,
-      crowdLabels: [],
-    );
-    await _patientManager.create(createPatientRequest);
-  }
 }
 
 class IdCardScanResult {

+ 0 - 18
lib/pages/id_card_scan/models.dart

@@ -1,19 +1 @@
-class IdCardInfoModel {
-  String idCardName;
-  String idCardGender;
-  String idCardNation;
-  String idCardBirthDate;
-  String idCardAddress;
-  String idCardNumber;
-  String localCardImagePath;
 
-  IdCardInfoModel({
-    this.idCardName = '',
-    this.idCardGender = '',
-    this.idCardNation = '',
-    this.idCardBirthDate = '',
-    this.idCardAddress = '',
-    this.idCardNumber = '',
-    this.localCardImagePath = '',
-  });
-}

+ 0 - 20
lib/pages/id_card_scan/state.dart

@@ -6,26 +6,6 @@ class IdCardScanState {
   set isCameraReady(value) => _isCameraReady.value = value;
   bool get isCameraReady => _isCameraReady.value;
 
-  /// 身份证信息是否展示
-  final _isIdCardInfoShow = false.obs;
-  set isIdCardInfoShow(value) => _isIdCardInfoShow.value = value;
-  bool get isIdCardInfoShow => _isIdCardInfoShow.value;
-
-  /// 是否显示身份信息开关
-  final _isShowIdCardInfoSwitch = false.obs;
-  set isShowIdCardInfoSwitch(value) => _isShowIdCardInfoSwitch.value = value;
-  bool get isShowIdCardInfoSwitch => _isShowIdCardInfoSwitch.value;
-
-  /// 是否进入人脸识别阶段
-  final _isInIdCardScan = false.obs;
-  set isInFaceInput(value) => _isInIdCardScan.value = value;
-  bool get isInFaceInput => _isInIdCardScan.value;
-
-  /// 是否展示人脸识别结果
-  final _isShowIdCardScanResult = false.obs;
-  set isShowIdCardScanResult(value) => _isShowIdCardScanResult.value = value;
-  bool get isShowIdCardScanResult => _isShowIdCardScanResult.value;
-
   /// 是否正在识别身份证
   final _isIdCardScanning = false.obs;
   set isIdCardScanning(value) => _isIdCardScanning.value = value;

+ 5 - 50
lib/pages/id_card_scan/view.dart

@@ -15,16 +15,11 @@ class IdCardScanPage extends GetView<IdCardScanController> {
       init: IdCardScanController(),
       builder: (_) {
         return Scaffold(
-          appBar: AppBar(
-              title: Obx(() =>
-                  Text(controller.state.isInFaceInput ? "人像采集" : "身份识别建档"))),
+          appBar: AppBar(title: const Text("身份识别建档")),
           body: SafeArea(
             child: Obx(
               () => controller.state.isCameraReady
                   ? _buildCameraArea()
-                  // ? CameraTestPage(
-                  //     cameras: controller.cameras,
-                  //   )
                   : const Center(
                       child: CircularProgressIndicator(
                         valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
@@ -40,7 +35,7 @@ class IdCardScanPage extends GetView<IdCardScanController> {
   Widget _buildCameraArea() {
     return Row(
       children: [
-        const IdCardInfo(),
+        // const IdCardInfo(),
         Expanded(
           child: ClipRRect(
             child: LayoutBuilder(builder: (context, constraints) {
@@ -56,19 +51,8 @@ class IdCardScanPage extends GetView<IdCardScanController> {
                       ),
                     ),
                   ),
-                  Center(
-                    child: Stack(
-                      children: [
-                        Align(
-                          alignment: Alignment.centerLeft,
-                          child: _idCardInfoSwitch(),
-                        ),
-                        // if (controller.state.isInFaceInput)
-                        //   const CameraForFace()
-                        // else
-                        const CameraForIdCard(),
-                      ],
-                    ),
+                  const Center(
+                    child: CameraForIdCard(),
                   ),
                 ],
               );
@@ -101,7 +85,7 @@ class IdCardScanPage extends GetView<IdCardScanController> {
                 onScaleUpdate: controller.handleScaleUpdate,
                 onTapDown: (TapDownDetails details) =>
                     controller.onViewFinderTap(details, constraints),
-                child: const FaceBoundingBox(),
+                child: Container(),
               );
             },
           ),
@@ -109,33 +93,4 @@ class IdCardScanPage extends GetView<IdCardScanController> {
       );
     }
   }
-
-  /// 身份证信息开关
-  Widget _idCardInfoSwitch() {
-    return Obx(
-      () {
-        if (!controller.state.isShowIdCardInfoSwitch) {
-          return Container();
-        }
-        return Container(
-          height: 80,
-          width: 40,
-          color: Colors.black.withOpacity(0.5),
-          child: IconButton(
-            onPressed: () {
-              controller.state.isIdCardInfoShow =
-                  !controller.state.isIdCardInfoShow;
-            },
-            padding: const EdgeInsets.all(0),
-            icon: Icon(
-                controller.state.isIdCardInfoShow
-                    ? Icons.keyboard_double_arrow_left
-                    : Icons.keyboard_double_arrow_right,
-                size: 30),
-            color: Colors.white,
-          ),
-        );
-      },
-    );
-  }
 }

+ 0 - 99
lib/pages/id_card_scan/widgets/camera_for_face.dart

@@ -1,99 +0,0 @@
-// import 'package:flutter/material.dart';
-// import 'package:get/get.dart';
-// import '../index.dart';
-
-// class CameraForFace extends GetView<IdCardScanController> {
-//   const CameraForFace({Key? key}) : super(key: key);
-
-//   @override
-//   Widget build(BuildContext context) {
-//     return Stack(
-//       children: <Widget>[
-//         // Align(
-//         //   alignment: Alignment.center,
-//         //   child: OverflowBox(
-//         //     maxHeight: 2000,
-//         //     maxWidth: 2000,
-//         //     child: Container(
-//         //       decoration: BoxDecoration(
-//         //         border: Border.all(
-//         //           color: const Color.fromARGB(80, 0, 0, 0),
-//         //           width: 500,
-//         //           strokeAlign: BorderSide.strokeAlignOutside,
-//         //         ),
-//         //         borderRadius: BorderRadius.circular(50),
-//         //       ),
-//         //       margin: const EdgeInsets.only(bottom: 110),
-//         //       child: const SizedBox(
-//         //         width: 465,
-//         //         height: 430,
-//         //       ),
-//         //     ),
-//         //   ),
-//         // ),
-//         Align(
-//           alignment: Alignment.center,
-//           child: Container(
-//             margin: const EdgeInsets.only(top: 80),
-//             child: const Image(
-//               image: AssetImage('assets/images/face_rec.png'),
-//               width: 800,
-//             ),
-//           ),
-//         ),
-//         Align(
-//           alignment: Alignment.centerRight,
-//           child: Container(
-//             child: _captureButton(),
-//           ),
-//         ),
-//         Align(
-//           alignment: Alignment.bottomCenter,
-//           child: Container(
-//             padding: const EdgeInsets.only(bottom: 40),
-//             child: const Text(
-//               '请将面部保持在识别框内,并确保面部清晰可见,然后按下拍摄键',
-//               style: TextStyle(color: Colors.white, fontSize: 22),
-//             ),
-//           ),
-//         ),
-//       ],
-//     );
-//   }
-
-//   /// 拍照按钮
-//   Widget _captureButton() {
-//     return Obx(() {
-//       if (controller.state.isRunningFaceInput) {
-//         return Container(
-//           margin: const EdgeInsets.only(right: 60),
-//           width: 100,
-//           height: 100,
-//           decoration: BoxDecoration(
-//             color: Colors.white,
-//             borderRadius: BorderRadius.circular(50),
-//           ),
-//           child: const Center(
-//             child: CircularProgressIndicator(
-//               color: Colors.blue,
-//             ),
-//           ),
-//         );
-//       }
-//       return Container(
-//         margin: const EdgeInsets.only(right: 60),
-//         width: 100,
-//         height: 100,
-//         decoration: BoxDecoration(
-//           color: Colors.white,
-//           borderRadius: BorderRadius.circular(50),
-//         ),
-//         child: IconButton(
-//           icon: const Icon(Icons.sensor_occupied, size: 50),
-//           color: Colors.blue,
-//           onPressed: controller.onCaptureFaceButtonPressed,
-//         ),
-//       );
-//     });
-//   }
-// }

+ 0 - 149
lib/pages/id_card_scan/widgets/face_bounding_box.dart

@@ -1,149 +0,0 @@
-import 'dart:math';
-
-import 'package:flutter/material.dart';
-import 'package:get/get.dart';
-import 'package:google_mlkit_face_detection/google_mlkit_face_detection.dart';
-import '../index.dart';
-
-class FaceBoundingBox extends GetView<IdCardScanController> {
-  const FaceBoundingBox({Key? key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return Obx(() {
-      if (!controller.state.isShowIdCardScanResult) {
-        return Container();
-      }
-      return Container(
-        padding: const EdgeInsets.all(10),
-        child: GetBuilder<IdCardScanController>(
-            id: 'face_bounding_box',
-            builder: (context) {
-              return CustomPaint(
-                size: Size.infinite,
-                painter: _FaceBoundingBoxPainter(
-                  faces: controller.kFrameFacesResult,
-                  sourceImageSize: controller.kFrameImageSize,
-                  isMirror: true,
-                ),
-              );
-            }),
-      );
-    });
-  }
-}
-
-class _FaceBoundingBoxPainter extends CustomPainter {
-  final List<Face> faces;
-
-  /// 是否镜像
-  final bool isMirror;
-
-  /// 原始图片大小
-  final Size sourceImageSize;
-
-  _FaceBoundingBoxPainter(
-      {required this.faces,
-      required this.isMirror,
-      required this.sourceImageSize});
-
-  @override
-  void paint(Canvas canvas, Size size) {
-    // 根据原始图片大小和当前画布大小,计算缩放比例
-    final scaleX = size.width / sourceImageSize.width;
-    final scaleY = size.height / sourceImageSize.height;
-    if (isMirror) {
-      canvas.scale(-scaleX, scaleY);
-      canvas.translate(-sourceImageSize.width, 0);
-    } else {
-      canvas.scale(scaleX, scaleY);
-      canvas.translate(0, 0);
-    }
-
-    for (final face in faces) {
-      /// 绘制关键点
-      // for (final FaceContour? contour in face.contours.values) {
-      //   if (contour == null) continue;
-      //   if (contour.points.isEmpty) continue;
-      //   if (contour.type == FaceContourType.face) {
-      //     // _drawContourPointsPath(canvas, size, contour.points);
-      //   } else {
-      //     // _drawContourPoints(canvas, size, contour.points);
-      //   }
-      // }
-
-      /// 绘制人脸框
-      _drawFaceRect(canvas, size, face.boundingBox);
-    }
-
-    /// 全屏画绿色
-    // final paint2 = Paint()
-    //   ..color = const Color.fromARGB(255, 36, 255, 36)
-    //   ..strokeWidth = 5
-    //   ..style = PaintingStyle.stroke;
-
-    // canvas.drawRect(
-    //   Rect.fromLTWH(0, 0, sourceImageSize.width, sourceImageSize.height),
-    //   paint2,
-    // );
-  }
-
-  /// 绘制contour连线
-  void _drawContourPointsPath(
-      Canvas canvas, Size size, List<Point<int>> points) {
-    final paint = Paint()
-      ..color = Colors.green
-      ..strokeWidth = 4
-      ..style = PaintingStyle.stroke;
-
-    final path = Path();
-    for (int i = 0; i < points.length; i++) {
-      final point = points[i];
-      if (i == 0) {
-        path.moveTo(
-          point.x.toDouble(),
-          point.y.toDouble(),
-        );
-        continue;
-      }
-      path.lineTo(
-        point.x.toDouble(),
-        point.y.toDouble(),
-      );
-    }
-    path.close();
-    canvas.drawPath(path, paint);
-  }
-
-  /// 绘制contour点集
-  void _drawContourPoints(Canvas canvas, Size size, List<Point<int>> points) {
-    final paint = Paint()
-      ..color = Colors.red
-      ..strokeWidth = 2
-      ..style = PaintingStyle.fill;
-
-    for (final point in points) {
-      canvas.drawCircle(
-        Offset(
-          point.x.toDouble(),
-          point.y.toDouble(),
-        ),
-        2,
-        paint,
-      );
-    }
-  }
-
-  /// 绘制人脸框
-  void _drawFaceRect(Canvas canvas, Size size, Rect rect) {
-    final paint = Paint()
-      ..color = Colors.green
-      ..strokeWidth = 3
-      ..style = PaintingStyle.stroke;
-
-    canvas.drawRect(rect, paint);
-  }
-
-  @override
-  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
-}

+ 0 - 153
lib/pages/id_card_scan/widgets/id_info.dart

@@ -1,153 +0,0 @@
-import 'dart:io';
-
-import 'package:flutter/material.dart';
-import 'package:get/get.dart';
-import '../index.dart';
-
-class IdCardInfo extends GetView<IdCardScanController> {
-  const IdCardInfo({Key? key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return Obx(
-      () => AnimatedContainer(
-        duration: const Duration(milliseconds: 300),
-        width: controller.state.isIdCardInfoShow ? 300 : 0,
-        color: const Color.fromARGB(255, 231, 231, 231),
-        child: OverflowBox(
-          maxWidth: 300,
-          minWidth: 300,
-          alignment: Alignment.centerRight,
-          child: Column(
-            children: [
-              const SizedBox(height: 20),
-              Container(
-                decoration: BoxDecoration(
-                  borderRadius: BorderRadius.circular(10),
-                ),
-                clipBehavior: Clip.antiAlias,
-                child: Transform.scale(
-                  scale:
-                      controller.idCardInfo.localCardImagePath == '' ? 1 : 1.8,
-                  child: Image.file(
-                    File(controller.idCardInfo.localCardImagePath),
-                    errorBuilder: (context, error, stackTrace) {
-                      return const Image(
-                        image: AssetImage('assets/images/id_card.png'),
-                        color: Colors.grey,
-                        width: 220,
-                      );
-                    },
-                    width: 220,
-                  ),
-                ),
-              ),
-              const SizedBox(height: 20),
-              Expanded(
-                child: Scrollbar(
-                  thumbVisibility: true,
-                  thickness: 10,
-                  radius: const Radius.circular(10),
-                  child: ListView(
-                    padding: const EdgeInsets.symmetric(horizontal: 20),
-                    children: [
-                      _buildLabel('姓名'),
-                      _buildValue(controller.idCardInfo.idCardName),
-                      const SizedBox(height: 10),
-                      _buildLabel('性别'),
-                      _buildValue(controller.idCardInfo.idCardGender),
-                      const SizedBox(height: 10),
-                      _buildLabel('民族'),
-                      _buildValue(controller.idCardInfo.idCardNation),
-                      const SizedBox(height: 10),
-                      _buildLabel('出生'),
-                      _buildValue(controller.idCardInfo.idCardBirthDate),
-                      const SizedBox(height: 10),
-                      _buildLabel('住址'),
-                      _buildValue(controller.idCardInfo.idCardAddress),
-                      const SizedBox(height: 10),
-                      _buildLabel('公民身份号码'),
-                      _buildValue(controller.idCardInfo.idCardNumber),
-                      const SizedBox(height: 10),
-                    ],
-                  ),
-                ),
-              ),
-              _buildCaptureAgainButton(),
-              const SizedBox(height: 10),
-            ],
-          ),
-        ),
-      ),
-    );
-  }
-
-  Widget _buildLabel(String label) {
-    return Row(
-      children: [
-        Padding(
-          padding: const EdgeInsets.only(left: 20),
-          child: Text(
-            label,
-            style: const TextStyle(color: Colors.grey, fontSize: 18),
-          ),
-        ),
-        Expanded(child: Container()),
-        // TODO 预留手动编辑入口
-        // InkWell(
-        //   onTap: () {},
-        //   child: Container(
-        //     padding:
-        //         const EdgeInsets.only(left: 20, top: 2, bottom: 2, right: 20),
-        //     child: const Icon(
-        //       Icons.border_color_outlined,
-        //       color: Colors.grey,
-        //       size: 20,
-        //     ),
-        //   ),
-        // ),
-      ],
-    );
-  }
-
-  Widget _buildValue(String value) {
-    return Align(
-      alignment: Alignment.centerLeft,
-      child: Padding(
-        padding: const EdgeInsets.only(left: 20),
-        child: Text(
-          value,
-          style: const TextStyle(color: Colors.black87, fontSize: 20),
-        ),
-      ),
-    );
-  }
-
-  Widget _buildCaptureAgainButton() {
-    return Align(
-      alignment: Alignment.center,
-      child: Row(
-        mainAxisAlignment: MainAxisAlignment.center,
-        children: [
-          const Text(
-            '身份证信息不正确?',
-            style: TextStyle(color: Colors.grey),
-          ),
-          TextButton(
-            onPressed: () {
-              controller.state.isUsingFrontCamera = false;
-              controller.state.isIdCardInfoShow = false;
-              controller.state.isShowIdCardInfoSwitch = false;
-              controller.state.isInFaceInput = false;
-              controller.openBackCamera();
-            },
-            child: const Text(
-              '重新拍摄',
-              style: TextStyle(color: Colors.blue),
-            ),
-          ),
-        ],
-      ),
-    );
-  }
-}

+ 0 - 3
lib/pages/id_card_scan/widgets/widgets.dart

@@ -2,6 +2,3 @@ library widgets;
 
 export './debug_camera.dart';
 export './camera_for_id_card.dart';
-export './camera_for_face.dart';
-export './id_info.dart';
-export './face_bounding_box.dart';