import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:gap/gap.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:ocbo_esign_mobile/functions/get_api.dart'; import 'package:ocbo_esign_mobile/widgets/box_widget.dart'; import 'package:ocbo_esign_mobile/widgets/text_widget.dart'; import 'package:vibration/vibration.dart'; class ValidatePage extends StatelessWidget { const ValidatePage({super.key}); @override Widget build(BuildContext context) { return const MaterialApp(debugShowCheckedModeBanner: false, home: BarcodeScannerScreen()); } } class BarcodeScannerScreen extends StatefulWidget { const BarcodeScannerScreen({super.key}); @override State createState() => _BarcodeScannerScreenState(); } class _BarcodeScannerScreenState extends State { late String qrResult = ''; void readQr(String value) async { if (value.contains('OCBO e-Sign')) { final response = await getApi('check-qr', value, null); final result = response["result"]; if (result != '') { setState(() { qrResult = result; }); } } else { setState(() { qrResult = 'invalid'; }); } } @override Widget build(BuildContext context) { return Scaffold( resizeToAvoidBottomInset: false, body: Container( alignment: Alignment.center, height: MediaQuery.of(context).size.height, decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color.fromRGBO(51, 34, 61, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(22, 33, 44, 1), Color.fromRGBO(30, 56, 50, 1), ], ), ), child: Center( child: Padding( padding: const EdgeInsets.only(top: 64, left: 16, right: 16), child: Column( children: [ Container( padding: EdgeInsets.only(top: 8, bottom: 8, left: 20, right: 20), decoration: BoxDecoration( color: const Color.fromRGBO(9, 13, 16, 0.725), borderRadius: BorderRadius.circular(32), ), child: const TextWidget(text: 'Scan OCBO e-Sign QR Code', size: 14, bold: true), ), const Gap(24), Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(36), border: BoxBorder.all(color: const Color.fromARGB(58, 227, 227, 227)), boxShadow: [ const BoxShadow( color: Color.fromRGBO(5, 5, 8, 0.526), blurRadius: 6, offset: Offset(4, 4), // left and up ), const BoxShadow( color: Color.fromRGBO(92, 71, 97, 0.526), blurRadius: 6, offset: Offset(-4, -4), // right and down ), ], ), height: 330, width: 340, child: ClipRRect( borderRadius: BorderRadius.circular(36), // Adjust the radius as needed child: MobileScanner( fit: BoxFit.cover, onDetect: (BarcodeCapture capture) async { final List barcodes = capture.barcodes; if (barcodes.isNotEmpty && barcodes.first.rawValue != null) { readQr(barcodes.first.rawValue!); if (await Vibration.hasVibrator()) { Vibration.vibrate(duration: 100); } } }, ), ), ), const Gap(24), if (qrResult.isNotEmpty) Column( children: [ if (qrResult != 'invalid') Row( children: [ Container( padding: EdgeInsets.all(0), width: 90, height: 90, decoration: BoxDecoration( color: const Color.fromRGBO(69, 191, 73, 0.1), border: Border.all(color: const Color.fromRGBO(69, 191, 73, 1), width: 2), borderRadius: BorderRadius.circular(99), // Optional: rounded corners ), child: Icon(Icons.check, color: const Color.fromRGBO(69, 191, 73, 1), size: 48), ), const Gap(24), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const TextWidget( text: 'Valid', bold: true, size: 22, color: Color.fromRGBO(69, 191, 73, 1), ), const Gap(16), const TextWidget( text: 'QR is a valid OCBO e-Sign', bold: false, size: 14, color: Color.fromRGBO(69, 191, 73, 1), ), ], ), const Gap(24), BoxWidget( title: '', content: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const TextWidget(text: 'Name', bold: true, size: 14), const Gap(8), TextWidget(text: qrResult, bold: false, size: 14), ], ), ), ], ) else Row( children: [ Container( padding: EdgeInsets.all(0), width: 90, height: 90, decoration: BoxDecoration( color: const Color.fromRGBO(206, 74, 77, 0.1), border: Border.all(color: const Color.fromRGBO(206, 74, 77, 1), width: 2), borderRadius: BorderRadius.circular(99), ), child: Icon(Icons.close, color: const Color.fromRGBO(206, 74, 77, 1), size: 48), ), const Gap(24), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const TextWidget( text: 'Invalid', bold: true, size: 22, color: Color.fromRGBO(206, 74, 77, 1), ), const Gap(16), const TextWidget( text: 'QR is a not valid OCBO e-Sign', bold: false, size: 14, color: Color.fromRGBO(206, 74, 77, 1), ), ], ), ], ), ], ), ], ), ), ), ), ); } }