view.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import 'package:camera/camera.dart';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/architecture/utils/advance_debounce.dart';
  6. import 'package:vitalapp/components/appbar.dart';
  7. import 'index.dart';
  8. import 'widgets/widgets.dart';
  9. class FacialRecognitionPage extends GetView<FacialRecognitionController> {
  10. const FacialRecognitionPage({
  11. Key? key,
  12. required this.mode,
  13. this.patientInfo,
  14. }) : super(key: key);
  15. final FacialRecognitionMode mode;
  16. final PatientDTO? patientInfo;
  17. @override
  18. Widget build(BuildContext context) {
  19. return GetBuilder<FacialRecognitionController>(
  20. init: FacialRecognitionController(
  21. mode: mode,
  22. patientInfo: patientInfo,
  23. ),
  24. builder: (_) {
  25. return Scaffold(
  26. appBar: VAppBar(
  27. titleText:
  28. mode == FacialRecognitionMode.faceInput ? "人像采集" : "人脸识别",
  29. ),
  30. body: SafeArea(
  31. child: Obx(
  32. () => controller.state.isCameraReady
  33. ? _buildCameraArea()
  34. : const Center(
  35. child: CircularProgressIndicator(
  36. valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
  37. ),
  38. ),
  39. ),
  40. ),
  41. );
  42. },
  43. );
  44. }
  45. Widget _buildCameraArea() {
  46. return Row(
  47. children: [
  48. Expanded(
  49. child: ClipRRect(
  50. child: LayoutBuilder(builder: (context, constraints) {
  51. return Stack(
  52. children: <Widget>[
  53. OverflowBox(
  54. maxHeight: constraints.maxHeight,
  55. maxWidth: 2000,
  56. child: Container(
  57. color: Colors.black,
  58. child: Center(
  59. child: _cameraPreviewWidget(),
  60. ),
  61. ),
  62. ),
  63. const Center(child: CameraForFace()),
  64. Align(
  65. alignment: Alignment.bottomRight,
  66. child: _switchCameraLens(),
  67. ),
  68. const ImageDetectingDialog(),
  69. ],
  70. );
  71. }),
  72. ),
  73. ),
  74. ],
  75. );
  76. }
  77. /// 相机预览
  78. Widget _cameraPreviewWidget() {
  79. final CameraController? cameraController = controller.kCameraController;
  80. if (cameraController == null || !cameraController.value.isInitialized) {
  81. /// 旋转loading
  82. return const Center(
  83. child: CircularProgressIndicator(),
  84. );
  85. } else {
  86. return Listener(
  87. onPointerDown: (_) => controller.pointers++,
  88. onPointerUp: (_) => controller.pointers--,
  89. child: CameraPreview(
  90. cameraController,
  91. child: LayoutBuilder(
  92. builder: (BuildContext context, BoxConstraints constraints) {
  93. return GestureDetector(
  94. behavior: HitTestBehavior.opaque,
  95. onScaleStart: controller.handleScaleStart,
  96. onScaleUpdate: controller.handleScaleUpdate,
  97. onTapDown: (TapDownDetails details) =>
  98. controller.onViewFinderTap(details, constraints),
  99. child: const FaceBoundingBox(),
  100. );
  101. },
  102. ),
  103. ),
  104. );
  105. }
  106. }
  107. Widget _switchCameraLens() {
  108. return Obx(() {
  109. if (controller.state.isRunningFaceRecognition) {
  110. return Container();
  111. }
  112. return GestureDetector(
  113. onTap: () {
  114. advanceDebounce(controller.switchCameraLens, "capture", 1500);
  115. },
  116. child: Container(
  117. padding: const EdgeInsets.all(10.0),
  118. // padding: const EdgeInsets.all(10),
  119. decoration: BoxDecoration(
  120. color: Colors.black.withOpacity(0.2),
  121. borderRadius: BorderRadius.circular(10),
  122. ),
  123. margin: const EdgeInsets.symmetric(horizontal: 40.0, vertical: 20.0),
  124. child: Column(
  125. mainAxisSize: MainAxisSize.min,
  126. children: [
  127. const Icon(
  128. Icons.camera_rear,
  129. size: 30,
  130. color: Colors.white,
  131. ),
  132. const SizedBox(height: 10),
  133. Text(
  134. controller.state.isUsingFrontCamera ? "切换为后置" : "切换为前置",
  135. style: const TextStyle(color: Colors.white),
  136. )
  137. ],
  138. ),
  139. ),
  140. );
  141. });
  142. }
  143. }