Skip to content

Commit

Permalink
feat: basic mobile scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 27, 2024
1 parent 3a81530 commit 9c088da
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions wallet/lib/pages/events/mobile_scanner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

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

@override
State<MobileQrScanner> createState() => _MobileQrScannerState();
}

class _MobileQrScannerState extends State<MobileQrScanner> {
Barcode? _barcode;

Widget _buildBarcode(Barcode? value) {
if (value == null) {
return const Text(
'Scan something!',
overflow: TextOverflow.fade,
style: TextStyle(color: Colors.white),
);
}

return Text(
value.displayValue ?? 'No display value.',
overflow: TextOverflow.fade,
style: const TextStyle(color: Colors.white),
);
}

void _handleBarcode(BarcodeCapture barcodes) {
if (mounted) {
setState(() {
_barcode = barcodes.barcodes.firstOrNull;
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Simple scanner')),
backgroundColor: Colors.black,
body: Stack(
children: [
MobileScanner(
onDetect: _handleBarcode,
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
alignment: Alignment.bottomCenter,
height: 100,
color: Colors.black.withOpacity(0.4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(child: Center(child: _buildBarcode(_barcode))),
],
),
),
),
],
),
);
}
}

0 comments on commit 9c088da

Please sign in to comment.