-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature-81/bulk-item-printing
- Loading branch information
Showing
5 changed files
with
106 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mobile_scanner/mobile_scanner.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:spare_parts/pages/item_page/item_page.dart'; | ||
import 'package:spare_parts/services/repositories/inventory_item_repository.dart'; | ||
import 'package:spare_parts/utilities/constants.dart'; | ||
|
||
class QRScanPage extends StatelessWidget { | ||
const QRScanPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final inventoryItemRepository = context.watch<InventoryItemRepository>(); | ||
final userRole = context.watch<UserRole>(); | ||
|
||
return Scaffold( | ||
appBar: AppBar(title: const Text('Mobile Scanner')), | ||
body: MobileScanner( | ||
fit: BoxFit.contain, | ||
onDetect: (capture) async { | ||
final List<Barcode> barcodes = capture.barcodes; | ||
|
||
if (barcodes.isNotEmpty) { | ||
try { | ||
final barcodeValue = barcodes.first.rawValue; | ||
print("IDDD: $barcodeValue"); | ||
|
||
final itemRef = await inventoryItemRepository | ||
.getItemDocumentReference(barcodeValue) | ||
.get(); | ||
|
||
if (itemRef.exists) { | ||
await Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => Provider.value( | ||
value: userRole, | ||
child: ItemPage( | ||
itemId: itemRef.id, | ||
), | ||
), | ||
), | ||
); | ||
} else { | ||
Navigator.pop(context); | ||
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
content: Text('Invalid QR Code: $barcodeValue'), | ||
backgroundColor: Theme.of(context).colorScheme.error, | ||
)); | ||
} | ||
} catch (e) { | ||
Navigator.pop(context); | ||
ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
content: Text('An error occured while scanning QR Code'), | ||
backgroundColor: Theme.of(context).colorScheme.error, | ||
)); | ||
} | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
|
||
<script defer | ||
src="https://s3.amazonaws.com/download.dymo.com/dymo/Software/JavaScript/dymo.connect.framework.js"></script> | ||
<script src="https://unpkg.com/@zxing/[email protected]" type="application/javascript"></script> | ||
|
||
<!-- This script adds the flutter initialization JS code --> | ||
<script src="flutter.js" defer></script> | ||
|