316 lines
12 KiB
Dart
316 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
import 'package:ocbo_esign_mobile/blocs/qr/functions/bloc_setqr.dart';
|
|
import 'package:ocbo_esign_mobile/functions/get_api.dart';
|
|
import 'package:ocbo_esign_mobile/widgets/button_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<BarcodeScannerScreen> createState() => _BarcodeScannerScreenState();
|
|
}
|
|
|
|
class _BarcodeScannerScreenState extends State<BarcodeScannerScreen> {
|
|
final Color _redColorShade = const Color.fromRGBO(86, 38, 38, 0.2);
|
|
final Color _redColor = const Color.fromRGBO(235, 88, 115, 0.91);
|
|
final Color _greenColorShade = const Color.fromARGB(51, 41, 115, 43);
|
|
final Color _greenColor = const Color.fromRGBO(76, 206, 81, 0.91);
|
|
|
|
late String _qrResult = '';
|
|
|
|
void readQr(String value) async {
|
|
if (value.contains('OCBO e-Sign')) {
|
|
final qr = value.substring(35);
|
|
final response = await getApi('check-qr', qr, null);
|
|
final result = response["result"].toString();
|
|
|
|
if (result != '') {
|
|
setState(() {
|
|
_qrResult = result;
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_qrResult = 'non-exist';
|
|
});
|
|
}
|
|
} else {
|
|
setState(() {
|
|
_qrResult = 'invalid';
|
|
});
|
|
|
|
Future.delayed(Duration(seconds: 3), () {
|
|
setState(() {
|
|
_qrResult = '';
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
void tryQR() async {
|
|
final value = "Use OCBO e-Sign Validator - scanid=0918d59e";
|
|
|
|
if (value.contains('OCBO e-Sign')) {
|
|
final qr = value.substring(35);
|
|
final response = await getApi('check-qr', qr, null);
|
|
final result = response["result"]?.toString();
|
|
|
|
if (result != null) {
|
|
setState(() {
|
|
_qrResult = result;
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_qrResult = 'non-exist';
|
|
});
|
|
|
|
Future.delayed(Duration(seconds: 3), () {
|
|
setState(() {
|
|
_qrResult = '';
|
|
});
|
|
});
|
|
}
|
|
} else {
|
|
setState(() {
|
|
_qrResult = 'invalid';
|
|
});
|
|
|
|
Future.delayed(Duration(seconds: 3), () {
|
|
setState(() {
|
|
_qrResult = '';
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
void updateBlockQr() async {
|
|
await blocSetQr(context, _qrResult);
|
|
}
|
|
|
|
void gotoDetails() {
|
|
updateBlockQr();
|
|
setState(() {
|
|
_qrResult = '';
|
|
});
|
|
|
|
context.push('/details');
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
body: Container(
|
|
alignment: Alignment.center,
|
|
height: MediaQuery.of(context).size.height * 1.2,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color.fromRGBO(37, 25, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(25, 46, 41, 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(16),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(36),
|
|
border: BoxBorder.all(color: const Color.fromARGB(64, 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: 308,
|
|
width: 318,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(36), // Adjust the radius as needed
|
|
child: MobileScanner(
|
|
fit: BoxFit.cover,
|
|
onDetect: (BarcodeCapture capture) async {
|
|
final List<Barcode> 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),
|
|
ButtonWidget(text: 'Try API', disabled: false, onPressed: tryQR),
|
|
if (_qrResult.isNotEmpty)
|
|
Column(
|
|
children: [
|
|
if (_qrResult == 'invalid')
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: 220,
|
|
padding: const EdgeInsets.fromLTRB(0, 16, 0, 32),
|
|
decoration: BoxDecoration(
|
|
border: BoxBorder.all(color: _redColor),
|
|
color: _redColorShade,
|
|
borderRadius: BorderRadius.circular(32),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
TextWidget(text: 'Invalid', bold: true, size: 24, color: _redColor),
|
|
const Gap(16),
|
|
Container(
|
|
width: 90,
|
|
height: 90,
|
|
decoration: BoxDecoration(
|
|
color: _redColorShade,
|
|
border: Border.all(color: _redColor, width: 2),
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Icon(Icons.close, color: _redColor, size: 48),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Gap(16),
|
|
Container(
|
|
padding: EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: _redColor, width: 2),
|
|
color: _redColorShade,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: TextWidget(
|
|
text: 'Not OCBO e-Sign QR detected',
|
|
bold: true,
|
|
size: 18,
|
|
color: _redColor,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
else if (_qrResult == 'non-exist')
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: 220,
|
|
padding: const EdgeInsets.fromLTRB(0, 16, 0, 32),
|
|
decoration: BoxDecoration(
|
|
border: BoxBorder.all(color: _redColor),
|
|
color: _redColorShade,
|
|
borderRadius: BorderRadius.circular(32),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
TextWidget(text: 'Unregistered', bold: true, size: 24, color: _redColor),
|
|
const Gap(16),
|
|
Container(
|
|
width: 90,
|
|
height: 90,
|
|
decoration: BoxDecoration(
|
|
color: _redColorShade,
|
|
border: Border.all(color: _redColor, width: 2),
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Icon(Icons.close, color: _redColor, size: 48),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Gap(16),
|
|
TextWidget(
|
|
text: 'OCBO e-Sign QR is not registered',
|
|
bold: true,
|
|
size: 20,
|
|
color: _redColor,
|
|
),
|
|
],
|
|
)
|
|
else
|
|
Column(
|
|
children: [
|
|
Container(
|
|
// width: MediaQuery.of(context).size.width - 160,
|
|
width: 220,
|
|
padding: const EdgeInsets.fromLTRB(0, 16, 0, 32),
|
|
decoration: BoxDecoration(
|
|
border: BoxBorder.all(color: _greenColor),
|
|
color: _greenColorShade,
|
|
borderRadius: BorderRadius.circular(32),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
TextWidget(text: 'Valid', bold: true, size: 24, color: _greenColor),
|
|
const Gap(16),
|
|
Container(
|
|
padding: EdgeInsets.all(0),
|
|
width: 90,
|
|
height: 90,
|
|
decoration: BoxDecoration(
|
|
color: _greenColorShade,
|
|
border: Border.all(color: _greenColor, width: 2),
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Icon(Icons.check, color: _greenColor, size: 48),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Gap(16),
|
|
TextWidget(text: _qrResult, bold: true, size: 18, color: _greenColor),
|
|
const Gap(16),
|
|
ButtonWidget(text: "Validate Applications", disabled: false, onPressed: gotoDetails),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|