ai_barcode_scanner 1.0.0-dev.1
ai_barcode_scanner: ^1.0.0-dev.1 copied to clipboard
A universal AI barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
example/lib/main.dart
import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String barcode = 'Tap to scan';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(' Scanner'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
child: const Text('Scan Barcode'),
onPressed: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => AiBarcodeScanner(
validator: (value) {
return value.startsWith('https://');
},
canPop: false,
onScan: (String value) {
debugPrint(value);
setState(() {
barcode = value;
});
},
onDetect: (p0) {},
onDispose: () {
debugPrint("Barcode scanner disposed!");
},
controller: MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
),
),
),
);
},
),
Text(barcode),
],
),
),
);
}
}