test base project
This commit is contained in:
@@ -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 BarcodeScreen extends StatefulWidget {
|
||||
const BarcodeScreen({super.key});
|
||||
|
||||
@override
|
||||
_BarcodeScreenState createState() => _BarcodeScreenState();
|
||||
}
|
||||
|
||||
class _BarcodeScreenState extends State<BarcodeScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
String scannedbar_code_scanner = 'No data';
|
||||
|
||||
// OLD scanBarcode via FlutterBarcodeScanner - removed no namespace AGP8 - by Azmat
|
||||
final MobileScannerController barCodeController = MobileScannerController(); // mobile_scanner controller - by Azmat
|
||||
Future<void> scanBarcode() async {
|
||||
final String? result = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('Scan Barcode')),
|
||||
body: MobileScanner(
|
||||
controller: barCodeController,
|
||||
onDetect: (capture) => Navigator.pop(
|
||||
context,
|
||||
capture.barcodes.isNotEmpty ? (capture.barcodes.first.rawValue ?? '') : '',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
scannedbar_code_scanner = result ?? '';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('BAR CODE')),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
'Scanned Barcode:',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
scannedbar_code_scanner,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
scanBarcode(); // Trigger barcode scanning
|
||||
},
|
||||
icon: const Icon(Icons.camera_alt), // Camera icon
|
||||
label: const Text('Scan Barcode'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
// import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
|
||||
import '../Barcode/Barcode_create_entity_screen.dart';
|
||||
import '../Qrcode/Qrcode_create_entity_screen.dart';
|
||||
|
||||
class QrBarCodeScreen extends StatefulWidget {
|
||||
const QrBarCodeScreen({super.key});
|
||||
|
||||
@override
|
||||
_QrBarCodeScreenState createState() => _QrBarCodeScreenState();
|
||||
}
|
||||
|
||||
class _QrBarCodeScreenState extends State<QrBarCodeScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
TextEditingController qr_code_dataController = TextEditingController();
|
||||
|
||||
// Function to show the QR code in a dialog
|
||||
void _showqr_code_dataDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Generated QR Code'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 200, // Set a fixed width for the QR code
|
||||
height: 200, // Set a fixed height for the QR code
|
||||
child: QrImageView(
|
||||
data: qr_code_dataController.text,
|
||||
version: QrVersions.auto,
|
||||
embeddedImageStyle:
|
||||
const QrEmbeddedImageStyle(size: Size(100, 100)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close the dialog
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TextEditingController bar_code_dataController = TextEditingController();
|
||||
|
||||
// Function to show the barcode in a dialog
|
||||
void _show_bar_code_dataDialog(String barcodeData) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Generated Bar Code'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Card(
|
||||
color: Colors.white,
|
||||
elevation: 6,
|
||||
shadowColor: Colors.amber,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: BarcodeWidget(
|
||||
data: barcodeData,
|
||||
barcode: Barcode.code128(),
|
||||
color: Colors.black,
|
||||
width: 200,
|
||||
height: 100,
|
||||
drawText: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close the dialog
|
||||
},
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('QR AND BAR CODE')),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
// GENERATE QR CODE
|
||||
TextFormField(
|
||||
controller: qr_code_dataController,
|
||||
decoration: const InputDecoration(labelText: 'qr_code_data'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_showqr_code_dataDialog();
|
||||
},
|
||||
child: const Text('Generate Qr')),
|
||||
|
||||
// GENERATE BAR CODE
|
||||
TextFormField(
|
||||
controller: bar_code_dataController,
|
||||
decoration: const InputDecoration(labelText: 'Bar Code Data'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_show_bar_code_dataDialog(bar_code_dataController.text);
|
||||
},
|
||||
child: const Text('Generate Bar code'),
|
||||
),
|
||||
// QR CODE SCANNER
|
||||
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const qrcodeScreen()));
|
||||
},
|
||||
child: const Text('QR Code Scanner'),
|
||||
),
|
||||
// BAR CODE SCANNER
|
||||
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const BarcodeScreen()));
|
||||
},
|
||||
child: const Text('Bar Code Scanner'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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