2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00
inventree-app/lib/barcode/wedge_controller.dart
Oliver c9cad2f89f
Some checks failed
Android / build (push) Has been cancelled
CI / test (push) Has been cancelled
iOS / build (push) Has been cancelled
Change from fontawesome to tabler icons (#516)
* Change from fontawesome to tabler icons

- Consistent with the frontend

* Cleanup conflicts

* Use double quotes

* remove unused import

* Update release notes

* Migrate some google icons to tabler icons

* Icon update

* Properly support display of custom icons

* Fix lookup
2024-08-08 19:44:44 +10:00

102 lines
2.6 KiB
Dart

import "package:flutter/material.dart";
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
import "package:inventree/app_colors.dart";
import "package:inventree/barcode/controller.dart";
import "package:inventree/barcode/handler.dart";
import "package:inventree/barcode/flutter_barcode_listener.dart";
import "package:inventree/l10.dart";
import "package:inventree/helpers.dart";
/*
* Barcode controller which acts as a keyboard wedge,
* intercepting barcode data which is entered as rapid keyboard presses
*/
class WedgeBarcodeController extends InvenTreeBarcodeController {
const WedgeBarcodeController(BarcodeHandler handler, {Key? key}) : super(handler, key: key);
@override
State<StatefulWidget> createState() => _WedgeBarcodeControllerState();
}
class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
_WedgeBarcodeControllerState() : super();
bool canScan = true;
bool get scanning => mounted && canScan;
@override
Future<void> pauseScan() async {
if (mounted) {
setState(() {
canScan = false;
});
}
}
@override
Future<void> resumeScan() async {
if (mounted) {
setState(() {
canScan = true;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(L10().scanBarcode),
),
backgroundColor: Colors.black.withOpacity(0.9),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Spacer(flex: 5),
Icon(TablerIcons.barcode, size: 64),
Spacer(flex: 5),
BarcodeKeyboardListener(
useKeyDownEvent: true,
child: SizedBox(
child: CircularProgressIndicator(
color: scanning ? COLOR_ACTION : COLOR_PROGRESS
),
width: 64,
height: 64,
),
onBarcodeScanned: (String barcode) {
debug("scanned: ${barcode}");
if (scanning) {
// Process the barcode data
handleBarcodeData(barcode);
}
},
),
Spacer(flex: 5),
Padding(
child: Text(
widget.handler.getOverlayText(context),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white)
),
padding: EdgeInsets.all(20),
)
],
)
)
);
}
}