base_project
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
// OLD: import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; // removed no namespace AGP8 - by Azmat
|
||||
import 'package:mobile_scanner/mobile_scanner.dart'; // migrated for AGP8 Java17 - by Azmat
|
||||
|
||||
class qrcodeScreen extends StatefulWidget {
|
||||
const qrcodeScreen({super.key});
|
||||
|
||||
@override
|
||||
_qrcodeScreenState createState() => _qrcodeScreenState();
|
||||
}
|
||||
|
||||
class _qrcodeScreenState extends State<qrcodeScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
String scannedqr_code_scanner = 'No data';
|
||||
|
||||
// OLD scanQRcode via FlutterBarcodeScanner - removed no namespace AGP8 - by Azmat
|
||||
final MobileScannerController qrCodeController = MobileScannerController(); // mobile_scanner controller - by Azmat
|
||||
Future<void> scanQRcode() async {
|
||||
final String? result = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('Scan QR')),
|
||||
body: MobileScanner(
|
||||
controller: qrCodeController,
|
||||
onDetect: (capture) => Navigator.pop(
|
||||
context,
|
||||
capture.barcodes.isNotEmpty ? (capture.barcodes.first.rawValue ?? '') : '',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
scannedqr_code_scanner = result ?? '';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('QR Code')),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
'Scanned QRcode:',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
scannedqr_code_scanner,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
scanQRcode(); // Trigger barcode scanning
|
||||
},
|
||||
icon: const Icon(Icons.camera_alt), // Camera icon
|
||||
label: const Text('Scan QRcode'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user