flexible_barcode_scanner 0.0.3
flexible_barcode_scanner: ^0.0.3 copied to clipboard
A highly customizable Flutter package for integrating a barcode scanner into your applications.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flexible_barcode_scanner/flexible_barcode_scanner.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Barcode Scanner',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Barcode Scanner'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String barcode = "";
void _scanBarcode() async {
final resultbarcode = await scanBarcode(
context,
);
setState(() {
if (resultbarcode != "-1") {
barcode = resultbarcode;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Below, the scanned barcode information will appear:',
),
Text(
barcode,
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _scanBarcode,
tooltip: 'Increment',
child: const Icon(Icons.barcode_reader),
),
);
}
}