Skip to content

Commit f07bef0

Browse files
committed
feat: Add barcode scanning functionality to home page
This commit adds barcode scanning functionality to the home page of the app. It replaces the previous overlay page with a new home page that includes a button to scan barcodes. When the button is pressed, the user is taken to a barcode scanner screen where they can scan barcodes. The scanned barcode is then displayed on the home page.
1 parent eac807c commit f07bef0

File tree

3 files changed

+55
-57
lines changed

3 files changed

+55
-57
lines changed

assets/final.PNG

-2.21 MB
Loading

example/lib/main.dart

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import 'package:example/pages/overlay.dart';
1+
import 'dart:developer';
2+
3+
import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
24
import 'package:flutter/material.dart';
35

46
void main() {
@@ -12,7 +14,58 @@ class MyApp extends StatelessWidget {
1214
@override
1315
Widget build(BuildContext context) {
1416
return const MaterialApp(
15-
home: OverlayPage(),
17+
home: HomePage(),
18+
);
19+
}
20+
}
21+
22+
class HomePage extends StatefulWidget {
23+
const HomePage({super.key});
24+
25+
@override
26+
State<HomePage> createState() => _HomePageState();
27+
}
28+
29+
class _HomePageState extends State<HomePage> {
30+
String barcode = 'Tap to scan';
31+
@override
32+
Widget build(BuildContext context) {
33+
return Scaffold(
34+
appBar: AppBar(
35+
title: const Text(' Scanner'),
36+
),
37+
body: Center(
38+
child: Column(
39+
mainAxisSize: MainAxisSize.min,
40+
children: [
41+
ElevatedButton(
42+
child: const Text('Scan Barcode'),
43+
onPressed: () async {
44+
await Navigator.of(context).push(
45+
MaterialPageRoute(
46+
builder: (context) => AiBarcodeScanner(
47+
onDispose: () {
48+
debugPrint("Barcode scanner disposed!");
49+
},
50+
controller: MobileScannerController(
51+
detectionSpeed: DetectionSpeed.noDuplicates,
52+
),
53+
onDetect: (p0) => setState(() {
54+
barcode = p0.barcodes.first.rawValue.toString();
55+
log(barcode, name: 'Barcode');
56+
}),
57+
validator: (p0) =>
58+
p0.barcodes.first.rawValue?.startsWith('https://') ??
59+
false,
60+
),
61+
),
62+
);
63+
},
64+
),
65+
Text(barcode),
66+
],
67+
),
68+
),
1669
);
1770
}
1871
}

example/lib/pages/overlay.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)