Untitled
unknown
plain_text
a year ago
10 kB
7
Indexable
class QRScreen extends StatefulWidget {
const QRScreen({super.key});
@override
State<QRScreen> createState() => _QRScreenState();
}
class _QRScreenState extends State<QRScreen> {
late MobileScannerController _controller;
QrCodeResponseModel? scannedData;
@override
void initState() {
super.initState();
_controller = MobileScannerController(
torchEnabled: false,
detectionSpeed: DetectionSpeed.noDuplicates,
);
// Listen to updates from the QR code API Rx
qrCodeApiRx.getAvailableSpecificItem.listen((data) {
setState(() {
scannedData = data; // Update the UI with scanned data
});
});
}
@override
void dispose() {
_controller.dispose();
qrCodeApiRx.dataFetcher.close(); // Dispose the stream
super.dispose();
}
// Triggered when a QR code is detected
void _onQrCodeDetected(String qrCodeValue) async {
final id = qrCodeValue; // Use the QR code value as needed
await qrCodeApiRx.getCheckedSpecificQrCode(id: id);
}
void _startScan() {
print('>>>>>>>>>>>>>>>>>>>>>>>>Tap the scan');
_controller.start();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
AiBarcodeScanner(
cutOutSize: 230,
cutOutBottomOffset: 200,
onDispose: () {
debugPrint("Barcode scanner disposed!");
},
appBarBuilder: (context, controller) => AppBar(
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: const Color(0XFF2F4C64),
leading: GestureDetector(
onTap: (){
NavigationService.goBack;
},
child: Padding(
padding: EdgeInsets.only(left: 10.w,),
child: Container(
width: 48.w,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage(Assets.icons.qrScreenBackIcon.path))
),
child: const Icon(Icons.arrow_back_ios_rounded,color: Colors.white,),
),
),
),
title: const Text(
"Scan QR code",
style: TextStyle(color: Colors.white),
),
),
extendBodyBehindAppBar: false,
borderColor: Colors.white,
overlayColor: const Color(0XFF2F4C64),
hideGalleryIcon: true,
hideSheetDragHandler: true,
hideSheetTitle: true,
hideGalleryButton: true,
bottomSheetBuilder: null,
borderRadius: 2,
borderWidth: 18,
borderLength: 30,
controller: _controller,
onDetect: (BarcodeCapture capture) {
final String? scannedValue = capture.barcodes.first.rawValue;
if (scannedValue != null) {
_onQrCodeDetected(scannedValue);
}
debugPrint("Barcode scanned: $scannedValue");
},
validator: (value) {
if (value.barcodes.isEmpty) {
return false;
}
return true;
},
),
Align(
alignment: Alignment.bottomCenter,
child: Positioned(
bottom: 40,
child: scanner_result(),
),
),
],
),
);
}
Padding scanner_result() {
return Padding(
padding: EdgeInsets.only(left: 25, right: 15,bottom: 60.h),
child: Container(
width: 327,
height: 322,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(image: AssetImage(Assets.images.qrSectionBg.path))
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(vertical:5 ),
child: ShaderMask(
shaderCallback: (bounds) => const LinearGradient(
colors: [Colors.blue, Colors.purple, Colors.red],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
).createShader(Rect.fromLTWH(0, 0, bounds.width, bounds.height)),
child: const Text(
'Result',
style: TextStyle(
fontSize: 23,
fontWeight: FontWeight.bold,
color: Colors.white, // Set the color for fallback
),
),
),
),
SizedBox(height: 10.h,),
Container(
height: 166,
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage(Assets.images.qrStatusBg.path)),
// color: Colors.white.withOpacity(.2),
borderRadius: BorderRadius.circular(25.r)),
child: Column(
children: [
SizedBox(height: 15.h,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
text: TextSpan(
text: "STATUS: ",
style: TextStyle(fontSize:20.sp, fontWeight: FontWeight.w600 ,color: Colors.white),
children: [
TextSpan(
text: scannedData?.status == true ? "OK" : "Not Valid",
style: TextStyle(fontSize:20, fontWeight: FontWeight.w600 ,color: scannedData?.status == true? Colors.white: const Color(0XFFFF4141)
)),
],
),
),
const SizedBox(width: 5,),
scannedData?.status == true ? SvgPicture.asset(Assets.icons.okIcon):SizedBox.shrink(),
],
),
const Padding(
padding:
EdgeInsets.symmetric(horizontal: 17, vertical: 12),
child: Divider(
color: Color(0x72D9D9D9),
),
),
scannedData?.status == true?Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: "Name: ",
style: TextStyle(
color: Colors.white.withOpacity(.3)),
children: [
TextSpan(
text: scannedData?.data?.user?.name ?? "Unknown",
style: const TextStyle(fontSize: 14,fontWeight: FontWeight.w400)),
],
),
),
const SizedBox(height: 15,),
RichText(
text: TextSpan(
text: "Name: ",
style: TextStyle(color: Colors.white.withOpacity(.3),fontWeight:FontWeight.w400,fontSize: 12 ),
children: [
TextSpan(
text: scannedData?.data?.event?.name ?? "No Event",
style: TextStyle(color: Colors.white.withOpacity(.3),fontWeight:FontWeight.w400,fontSize: 12 )),
],
),
),
],
):
Image.asset(Assets.images.crossImage.path)
],
),
),
const SizedBox(height: 20,),
ActionButton(
onTap: (){
_startScan();
},
btnNm: "Scan Again ",
btnIcon: Assets.icons.qrscanIcon,
)
],
),
),
),
);
}
}
class ActionButton extends StatelessWidget {
const ActionButton({
super.key,
required this.btnNm,
this.width,
this.height,
this.onTap, this.btnIcon,
this.isLoading = false
});
final String btnNm;
final String? btnIcon;
final double? width;
final double ? height;
final VoidCallback? onTap;
final bool isLoading;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (onTap != null) {
onTap!();
}
},
child: Container(
width: width ?? double.infinity,
height: height ?? 56,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: const LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
colors: [
Color(0xFFF54650),
Color(0xFFCD6AD2),
Color(0xFF38B7FF)
],
),
),
child: isLoading? const CircularProgressIndicator() : Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
btnNm, style: TextStyle(fontSize: 18.sp,color: Colors.white),
),
const SizedBox(height: 15,),
if(btnIcon !=null) SvgPicture.asset(btnIcon.toString())
],
),
),
);
}
}Editor is loading...
Leave a Comment