import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/global.dart';
import '../index.dart';

class ImageDetectingDialog extends GetView<IdCardScanController> {
  const ImageDetectingDialog({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(
      () {
        if (controller.state.processingImageLocalPath.isEmpty) {
          return Container();
        }
        return Center(
          child: Stack(
            children: [
              ModalBarrier(
                color: Colors.black.withOpacity(0.5),
                dismissible: false,
              ),
              Center(
                child: Container(
                  width: 850,
                  height: 600,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                  ),
                  clipBehavior: Clip.antiAlias,
                  padding: const EdgeInsets.all(40),
                  child: Column(
                    children: [
                      Stack(
                        children: [
                          Center(
                            child: Container(
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(10),
                              ),
                              clipBehavior: Clip.antiAlias,
                              child: Image(
                                image: FileImage(
                                    // kIsOnline ||
                                    //         controller.state
                                    //                 .processingImageUint8List ==
                                    //             null
                                    //     ?
                                    File(controller
                                        .state.processingImageLocalPath)
                                    // : File.fromRawPath(controller
                                    //     .state.processingImageUint8List!),
                                    ),
                                fit: BoxFit.cover,
                              ),
                            ),
                          ),
                        ],
                      ),
                      const SizedBox(height: 40),
                      Expanded(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: const [
                            SizedBox(
                              height: 20,
                              width: 20,
                              child: CircularProgressIndicator(
                                valueColor:
                                    AlwaysStoppedAnimation<Color>(Colors.blue),
                              ),
                            ),
                            SizedBox(
                              width: 20,
                            ),
                            Text(
                              '身份证信息识别中，请稍后...',
                              style: TextStyle(
                                  fontSize: 16, color: Colors.black54),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              // 旋转的 loading
            ],
          ),
        );
      },
    );
  }
}
