mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-01 19:30:44 +00:00
Format Code and Add Format Checks to CI (#643)
* Remove unused lib/generated/i18n.dart * Use `fvm dart format .` * Add contributing guidelines * Enforce dart format * Add `dart format off` directive to generated files
This commit is contained in:
@ -10,7 +10,6 @@ import "package:inventree/widget/company/manufacturer_part_detail.dart";
|
||||
import "package:inventree/widget/order/sales_order_detail.dart";
|
||||
import "package:one_context/one_context.dart";
|
||||
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
@ -35,10 +34,8 @@ import "package:inventree/widget/stock/stock_detail.dart";
|
||||
import "package:inventree/widget/company/company_detail.dart";
|
||||
import "package:inventree/widget/company/supplier_part_detail.dart";
|
||||
|
||||
|
||||
// Signal a barcode scan success to the user
|
||||
Future<void> barcodeSuccess(String msg) async {
|
||||
|
||||
barcodeSuccessTone();
|
||||
showSnackIcon(msg, success: true);
|
||||
}
|
||||
@ -47,24 +44,23 @@ Future<void> barcodeSuccess(String msg) async {
|
||||
Future<void> barcodeFailure(String msg, dynamic extra) async {
|
||||
barcodeFailureTone();
|
||||
showSnackIcon(
|
||||
msg,
|
||||
success: false,
|
||||
msg,
|
||||
success: false,
|
||||
onAction: () {
|
||||
if (hasContext()) {
|
||||
OneContext().showDialog(
|
||||
builder: (BuildContext context) =>
|
||||
SimpleDialog(
|
||||
title: Text(L10().barcodeError),
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(L10().responseData),
|
||||
subtitle: Text(extra.toString())
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (hasContext()) {
|
||||
OneContext().showDialog(
|
||||
builder: (BuildContext context) => SimpleDialog(
|
||||
title: Text(L10().barcodeError),
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(L10().responseData),
|
||||
subtitle: Text(extra.toString()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -75,15 +71,22 @@ Future<void> barcodeFailure(String msg, dynamic extra) async {
|
||||
* - Returns a Future which resolves when the scanner is dismissed
|
||||
* - The provided BarcodeHandler instance is used to handle the scanned barcode
|
||||
*/
|
||||
Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) async {
|
||||
|
||||
Future<Object?> scanBarcode(
|
||||
BuildContext context, {
|
||||
BarcodeHandler? handler,
|
||||
}) async {
|
||||
// Default to generic scan handler
|
||||
handler ??= BarcodeScanHandler();
|
||||
|
||||
|
||||
InvenTreeBarcodeController controller = CameraBarcodeController(handler);
|
||||
|
||||
// Select barcode controller based on user preference
|
||||
final int barcodeControllerType = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_TYPE, BARCODE_CONTROLLER_CAMERA) as int;
|
||||
final int barcodeControllerType =
|
||||
await InvenTreeSettingsManager().getValue(
|
||||
INV_BARCODE_SCAN_TYPE,
|
||||
BARCODE_CONTROLLER_CAMERA,
|
||||
)
|
||||
as int;
|
||||
|
||||
switch (barcodeControllerType) {
|
||||
case BARCODE_CONTROLLER_WEDGE:
|
||||
@ -95,14 +98,10 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
|
||||
}
|
||||
|
||||
return Navigator.of(context).push(
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, _, _) => controller,
|
||||
opaque: false,
|
||||
)
|
||||
PageRouteBuilder(pageBuilder: (context, _, _) => controller, opaque: false),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class for general barcode scanning.
|
||||
* Scan *any* barcode without context, and then redirect app to correct view.
|
||||
@ -116,19 +115,17 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
|
||||
* - PurchaseOrder
|
||||
*/
|
||||
class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => L10().barcodeScanGeneral;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||
|
||||
barcodeFailureTone();
|
||||
|
||||
showSnackIcon(
|
||||
L10().barcodeNoMatch,
|
||||
icon: TablerIcons.exclamation_circle,
|
||||
success: false,
|
||||
L10().barcodeNoMatch,
|
||||
icon: TablerIcons.exclamation_circle,
|
||||
success: false,
|
||||
);
|
||||
}
|
||||
|
||||
@ -136,12 +133,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
* Response when a "Part" instance is scanned
|
||||
*/
|
||||
Future<void> handlePart(int pk) async {
|
||||
|
||||
var part = await InvenTreePart().get(pk);
|
||||
|
||||
if (part is InvenTreePart) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(builder: (context) => PartDetailWidget(part)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,13 +147,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
* Response when a "StockItem" instance is scanned
|
||||
*/
|
||||
Future<void> handleStockItem(int pk) async {
|
||||
|
||||
var item = await InvenTreeStockItem().get(pk);
|
||||
|
||||
if (item is InvenTreeStockItem) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => StockDetailWidget(item)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(builder: (context) => StockDetailWidget(item)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,13 +161,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
* Response when a "StockLocation" instance is scanned
|
||||
*/
|
||||
Future<void> handleStockLocation(int pk) async {
|
||||
|
||||
var loc = await InvenTreeStockLocation().get(pk);
|
||||
|
||||
if (loc is InvenTreeStockLocation) {
|
||||
OneContext().pop();
|
||||
OneContext().navigator.push(MaterialPageRoute(
|
||||
builder: (context) => LocationDisplayWidget(loc)));
|
||||
OneContext().navigator.push(
|
||||
MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,13 +175,15 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
* Response when a "SupplierPart" instance is scanned
|
||||
*/
|
||||
Future<void> handleSupplierPart(int pk) async {
|
||||
|
||||
var supplierPart = await InvenTreeSupplierPart().get(pk);
|
||||
|
||||
if (supplierPart is InvenTreeSupplierPart) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => SupplierPartDetailWidget(supplierPart)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SupplierPartDetailWidget(supplierPart),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,8 +195,11 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
if (manufacturerPart is InvenTreeManufacturerPart) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,8 +208,9 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
if (company is InvenTreeCompany) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => CompanyDetailWidget(company)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(builder: (context) => CompanyDetailWidget(company)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,8 +222,11 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
if (order is InvenTreePurchaseOrder) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => PurchaseOrderDetailWidget(order)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PurchaseOrderDetailWidget(order),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,8 +236,9 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
if (order is InvenTreeSalesOrder) {
|
||||
OneContext().pop();
|
||||
OneContext().push(MaterialPageRoute(
|
||||
builder: (context) => SalesOrderDetailWidget(order)));
|
||||
OneContext().push(
|
||||
MaterialPageRoute(builder: (context) => SalesOrderDetailWidget(order)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +258,6 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
InvenTreeManufacturerPart.MODEL_TYPE,
|
||||
];
|
||||
|
||||
|
||||
if (InvenTreeAPI().supportsOrderBarcodes) {
|
||||
validModels.add(InvenTreePurchaseOrder.MODEL_TYPE);
|
||||
validModels.add(InvenTreeSalesOrder.MODEL_TYPE);
|
||||
@ -274,7 +281,6 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
// A valid result has been found
|
||||
if (pk > 0 && model.isNotEmpty) {
|
||||
|
||||
barcodeSuccessTone();
|
||||
|
||||
switch (model) {
|
||||
@ -312,35 +318,31 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
barcodeFailureTone();
|
||||
|
||||
showSnackIcon(
|
||||
L10().barcodeUnknown,
|
||||
success: false,
|
||||
onAction: () {
|
||||
|
||||
if (hasContext()) {
|
||||
OneContext().showDialog(
|
||||
builder: (BuildContext context) =>
|
||||
SimpleDialog(
|
||||
title: Text(L10().unknownResponse),
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(L10().responseData),
|
||||
subtitle: Text(data.toString()),
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
L10().barcodeUnknown,
|
||||
success: false,
|
||||
onAction: () {
|
||||
if (hasContext()) {
|
||||
OneContext().showDialog(
|
||||
builder: (BuildContext context) => SimpleDialog(
|
||||
title: Text(L10().unknownResponse),
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(L10().responseData),
|
||||
subtitle: Text(data.toString()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Barcode handler for finding a "unique" barcode (one that does not match an item in the database)
|
||||
*/
|
||||
class UniqueBarcodeHandler extends BarcodeHandler {
|
||||
|
||||
UniqueBarcodeHandler(this.callback, {this.overlayText = ""});
|
||||
|
||||
// Callback function when a "unique" barcode hash is found
|
||||
@ -360,11 +362,7 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||
if (!data.containsKey("hash") && !data.containsKey("barcode_hash")) {
|
||||
showServerError(
|
||||
"barcode/",
|
||||
L10().missingData,
|
||||
L10().barcodeMissingHash,
|
||||
);
|
||||
showServerError("barcode/", L10().missingData, L10().barcodeMissingHash);
|
||||
} else {
|
||||
String barcode;
|
||||
|
||||
@ -373,12 +371,8 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
||||
if (barcode.isEmpty) {
|
||||
barcodeFailureTone();
|
||||
|
||||
showSnackIcon(
|
||||
L10().barcodeError,
|
||||
success: false,
|
||||
);
|
||||
showSnackIcon(L10().barcodeError, success: false);
|
||||
} else {
|
||||
|
||||
barcodeSuccessTone();
|
||||
|
||||
// Close the barcode scanner
|
||||
@ -395,41 +389,43 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||
await onBarcodeMatched(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
|
||||
|
||||
SpeedDialChild customBarcodeAction(
|
||||
BuildContext context,
|
||||
RefreshableState state,
|
||||
String barcode,
|
||||
String model,
|
||||
int pk,
|
||||
) {
|
||||
if (barcode.isEmpty) {
|
||||
return SpeedDialChild(
|
||||
label: L10().barcodeAssign,
|
||||
child: Icon(Icons.barcode_reader),
|
||||
onTap: () {
|
||||
var handler = UniqueBarcodeHandler((String barcode) {
|
||||
InvenTreeAPI().linkBarcode({
|
||||
model: pk.toString(),
|
||||
"barcode": barcode,
|
||||
}).then((bool result) {
|
||||
showSnackIcon(
|
||||
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
||||
success: result
|
||||
);
|
||||
InvenTreeAPI()
|
||||
.linkBarcode({model: pk.toString(), "barcode": barcode})
|
||||
.then((bool result) {
|
||||
showSnackIcon(
|
||||
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
||||
success: result,
|
||||
);
|
||||
|
||||
state.refresh(context);
|
||||
});
|
||||
state.refresh(context);
|
||||
});
|
||||
});
|
||||
scanBarcode(context, handler: handler);
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return SpeedDialChild(
|
||||
child: Icon(Icons.barcode_reader),
|
||||
label: L10().barcodeUnassign,
|
||||
onTap: () {
|
||||
InvenTreeAPI().unlinkBarcode({
|
||||
model: pk.toString()
|
||||
}).then((bool result) {
|
||||
InvenTreeAPI().unlinkBarcode({model: pk.toString()}).then((
|
||||
bool result,
|
||||
) {
|
||||
showSnackIcon(
|
||||
result ? L10().requestSuccessful : L10().requestFailed,
|
||||
success: result,
|
||||
@ -437,7 +433,7 @@ SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state,
|
||||
|
||||
state.refresh(context);
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user