Skip to content

Commit

Permalink
feat: Add barcode scanning functionality to home page
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rvndsngwn committed May 25, 2024
1 parent eac807c commit f07bef0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 57 deletions.
Binary file modified assets/final.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 55 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:example/pages/overlay.dart';
import 'dart:developer';

import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -12,7 +14,58 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: OverlayPage(),
home: HomePage(),
);
}
}

class HomePage extends StatefulWidget {
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
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(
onDispose: () {
debugPrint("Barcode scanner disposed!");
},
controller: MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates,
),
onDetect: (p0) => setState(() {
barcode = p0.barcodes.first.rawValue.toString();
log(barcode, name: 'Barcode');
}),
validator: (p0) =>
p0.barcodes.first.rawValue?.startsWith('https://') ??
false,
),
),
);
},
),
Text(barcode),
],
),
),
);
}
}
55 changes: 0 additions & 55 deletions example/lib/pages/overlay.dart

This file was deleted.

0 comments on commit f07bef0

Please sign in to comment.