view.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ? _buildCameraArea()
  23. : const Center(
  24. child: CircularProgressIndicator(
  25. valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
  26. ),
  27. ),
  28. ),
  29. ),
  30. );
  31. },
  32. );
  33. }
  34. Widget _buildCameraArea() {
  35. return Row(
  36. children: [
  37. // const IdCardInfo(),
  38. Expanded(
  39. child: ClipRRect(
  40. child: LayoutBuilder(builder: (context, constraints) {
  41. return Stack(
  42. children: <Widget>[
  43. OverflowBox(
  44. maxHeight: constraints.maxHeight,
  45. maxWidth: 2000,
  46. child: Container(
  47. color: Colors.black,
  48. child: Center(
  49. child: _cameraPreviewWidget(),
  50. ),
  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 GestureDetector(
  82. behavior: HitTestBehavior.opaque,
  83. onScaleStart: controller.handleScaleStart,
  84. onScaleUpdate: controller.handleScaleUpdate,
  85. onTapDown: (TapDownDetails details) =>
  86. controller.onViewFinderTap(details, constraints),
  87. child: Container(),
  88. );
  89. },
  90. ),
  91. ),
  92. );
  93. }
  94. }
  95. }