code_scan 0.4.2 code_scan: ^0.4.2 copied to clipboard
A flexible code scanner for QR codes, barcodes and many others. Using Google's ML Kit. Use it as a Widget with a camera or use the methods provided, with a camera controller.
import 'package:flutter/material.dart';
import 'package:code_scan/code_scan.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
String? code;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: code == null
? CodeScanner(
onScan: (code, details, controller) =>
setState(() => this.code = code),
onScanAll: (codes, controller) => print(
'Codes: ' + codes.map((code) => code.rawValue).toString()),
formats: const [BarcodeFormat.qrCode],
once: true,
)
: GestureDetector(
onTap: () => setState(() => code = null),
child: Container(
color: Colors.transparent,
child: Center(child: Text(code!)),
),
),
),
);
}
}