view.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:camera/camera.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/components/appbar.dart';
  5. import 'index.dart';
  6. import 'widgets/widgets.dart';
  7. // import 'package:video_player/video_player.dart';
  8. class IdCardScanPage extends GetView<IdCardScanController> {
  9. const IdCardScanPage({Key? key}) : super(key: key);
  10. @override
  11. Widget build(BuildContext context) {
  12. return GetBuilder<IdCardScanController>(
  13. init: IdCardScanController(),
  14. builder: (_) {
  15. return Scaffold(
  16. appBar: VAppBar(
  17. titleText: "身份证识别",
  18. ),
  19. body: SafeArea(
  20. child: Obx(
  21. () => controller.state.isCameraReady
  22. ? Container(
  23. color: Colors.black,
  24. child: _buildCameraArea(),
  25. )
  26. : const Center(
  27. child: CircularProgressIndicator(
  28. valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
  29. ),
  30. ),
  31. ),
  32. ),
  33. );
  34. },
  35. );
  36. }
  37. Widget _buildCameraArea() {
  38. return Row(
  39. children: [
  40. // const IdCardInfo(),
  41. Expanded(
  42. child: ClipRRect(
  43. child: LayoutBuilder(builder: (context, constraints) {
  44. return Stack(
  45. children: <Widget>[
  46. OverflowBox(
  47. child: AspectRatio(
  48. aspectRatio:
  49. controller.kCameraController?.value.aspectRatio ?? 1,
  50. child: _cameraPreviewWidget(),
  51. ),
  52. ),
  53. const Center(
  54. child: CameraForIdCard(),
  55. ),
  56. const ImageDetectingDialog(),
  57. ],
  58. );
  59. }),
  60. ),
  61. ),
  62. ],
  63. );
  64. }
  65. /// 相机预览
  66. Widget _cameraPreviewWidget() {
  67. final CameraController? cameraController = controller.kCameraController;
  68. if (cameraController == null || !cameraController.value.isInitialized) {
  69. /// 旋转loading
  70. return const Center(
  71. child: CircularProgressIndicator(),
  72. );
  73. } else {
  74. return Listener(
  75. onPointerDown: (_) => controller.pointers++,
  76. onPointerUp: (_) => controller.pointers--,
  77. child: CameraPreview(
  78. cameraController,
  79. child: LayoutBuilder(
  80. builder: (BuildContext context, BoxConstraints constraints) {
  81. return FittedBox(
  82. child: GestureDetector(
  83. behavior: HitTestBehavior.opaque,
  84. onScaleStart: controller.handleScaleStart,
  85. onScaleUpdate: controller.handleScaleUpdate,
  86. onTapDown: (TapDownDetails details) =>
  87. controller.onViewFinderTap(details, constraints),
  88. child: Container(),
  89. ),
  90. );
  91. },
  92. ),
  93. ),
  94. );
  95. }
  96. }
  97. }