import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';

import '../Notifiers/scanLoginProvider.dart';
import '../Utils/app_colors.dart';
import '../Utils/commonWidgets.dart';

class Scannerlogin extends StatefulWidget {
  const Scannerlogin({super.key});

  @override
  State<Scannerlogin> createState() => _ScannerloginState();
}

class _ScannerloginState extends State<Scannerlogin> {
  @override
  Widget build(BuildContext context) {
    return Consumer<Scanloginprovider>(
      builder: (context, provider, child) {
        return WillPopScope(
          onWillPop: () => onBackPressed(context),
          child: Scaffold(
            resizeToAvoidBottomInset: true,
            backgroundColor: AppColors.scaffold_bg_color,
            appBar: appbar(context, "QR Login"),
            body: SafeArea(
              child: Container(
                decoration: BoxDecoration(color: Colors.black),
                child: Column(
                  children: [
                    Spacer(),
                    Container(
                      height: 250,
              
                      child: QRView(
              
                        key: provider.scannerKey,
                        onQRViewCreated: (p0) {
                          provider.onQRViewCreated(p0, context);
                        },
                        formatsAllowed: [BarcodeFormat.qrcode],
                        cameraFacing: CameraFacing.back,
              
                        overlay: QrScannerOverlayShape(
              
                          borderColor: AppColors.app_blue,
                          borderRadius: 20,
                          borderLength: 60,
                          borderWidth: 10,
                          cutOutSize: 250.0,
                        ),
                      ),
                    ),
                    SizedBox(height: 25),
                    Text(
                      "Scan QR",
                      textAlign: TextAlign.center,
                      style: TextStyle(fontSize: 18, color: Colors.white),
                    ),
                    Text(
                      "to Login",
                      textAlign: TextAlign.center,
                      style: TextStyle(fontSize: 14, color: Colors.white),
                    ),
                    Spacer(),
              
                    SizedBox(height: 50),
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
