123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import 'package:camera/camera.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'index.dart';
- import 'widgets/widgets.dart';
- // import 'package:video_player/video_player.dart';
- class IdCardScanPage extends GetView<IdCardScanController> {
- const IdCardScanPage({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return GetBuilder<IdCardScanController>(
- init: IdCardScanController(),
- builder: (_) {
- return Scaffold(
- 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),
- ),
- ),
- ),
- ),
- );
- },
- );
- }
- Widget _buildCameraArea() {
- return Row(
- children: [
- const IdCardInfo(),
- Expanded(
- child: ClipRRect(
- child: LayoutBuilder(builder: (context, constraints) {
- return Stack(
- children: <Widget>[
- OverflowBox(
- maxHeight: constraints.maxHeight,
- maxWidth: 2000,
- child: Container(
- color: Colors.black,
- child: Center(
- child: _cameraPreviewWidget(),
- ),
- ),
- ),
- Center(
- child: Stack(
- children: [
- Align(
- alignment: Alignment.centerLeft,
- child: _idCardInfoSwitch(),
- ),
- if (controller.state.isInIdCardScan)
- const CameraForFace()
- else
- const CameraForIdCard(),
- ],
- ),
- ),
- ],
- );
- }),
- ),
- ),
- ],
- );
- }
- /// 相机预览
- Widget _cameraPreviewWidget() {
- final CameraController? cameraController = controller.kCameraController;
- if (cameraController == null || !cameraController.value.isInitialized) {
- /// 旋转loading
- return const Center(
- child: CircularProgressIndicator(),
- );
- } else {
- return Listener(
- onPointerDown: (_) => controller.pointers++,
- onPointerUp: (_) => controller.pointers--,
- child: CameraPreview(
- cameraController,
- child: LayoutBuilder(
- builder: (BuildContext context, BoxConstraints constraints) {
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onScaleStart: controller.handleScaleStart,
- onScaleUpdate: controller.handleScaleUpdate,
- onTapDown: (TapDownDetails details) =>
- controller.onViewFinderTap(details, constraints),
- child: const FaceBoundingBox(),
- );
- },
- ),
- ),
- );
- }
- }
- /// 身份证信息开关
- 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,
- ),
- );
- },
- );
- }
- }
|