mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 10:15:32 +00:00
snack bar now uses OneContext()
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
import 'package:InvenTree/widget/dialogs.dart';
|
||||
import 'package:InvenTree/widget/snacks.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:one_context/one_context.dart';
|
||||
|
||||
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||
|
||||
@ -139,6 +141,19 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) {
|
||||
|
||||
showSnackIcon(
|
||||
"No barcode",
|
||||
icon: FontAwesomeIcons.exclamationCircle,
|
||||
onTap: () {
|
||||
print("Tappity");
|
||||
},
|
||||
success: true,
|
||||
);
|
||||
|
||||
_controller.resumeCamera();
|
||||
|
||||
/*
|
||||
showErrorDialog(
|
||||
_context,
|
||||
data['error'] ?? '',
|
||||
@ -149,6 +164,8 @@ class BarcodeScanHandler extends BarcodeHandler {
|
||||
_controller.resumeCamera();
|
||||
}
|
||||
);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@override
|
||||
@ -385,14 +402,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
||||
// If the barcode points to a 'stocklocation', great!
|
||||
if (!data.containsKey('stocklocation')) {
|
||||
showErrorDialog(
|
||||
_context,
|
||||
"Invalid Barcode",
|
||||
"Barcode does not match a Stock Location",
|
||||
onDismissed: _controller.resumeCamera,
|
||||
);
|
||||
} else {
|
||||
if (data.containsKey('stocklocation')) {
|
||||
// Extract location information
|
||||
int location = data['stocklocation']['pk'] as int;
|
||||
|
||||
@ -402,11 +412,35 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
||||
_controller.dispose();
|
||||
Navigator.of(_context).pop();
|
||||
});
|
||||
} else {
|
||||
// Display a snack bar with the error
|
||||
OneContext().showSnackBar(builder: (context) => SnackBar(
|
||||
content: Text("This was not a stock item!")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StockLocationScanInItemsHandler extends BarcodeHandler {
|
||||
/**
|
||||
* Barcode handler for scanning stock item(s) into the specified StockLocation
|
||||
*/
|
||||
|
||||
final InvenTreeStockLocation location;
|
||||
|
||||
StockLocationScanInItemsHandler(this.location);
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanItem;
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
||||
print("TODO, YO!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> scanQrCode(BuildContext context) async {
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView(BarcodeScanHandler())));
|
||||
|
@ -91,7 +91,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
final bool result = await part.update(context, values: values);
|
||||
|
||||
showSnackIcon(
|
||||
refreshableKey,
|
||||
result ? "Part edited" : "Part editing failed",
|
||||
success: result
|
||||
);
|
||||
|
@ -11,26 +11,44 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:one_context/one_context.dart';
|
||||
|
||||
void showSnackIcon(GlobalKey<ScaffoldState> key, String text, {IconData icon, bool success}) {
|
||||
void showSnackIcon(String text, {IconData icon, Function onTap, bool success}) {
|
||||
|
||||
// Hide the current snackbar
|
||||
key.currentState.hideCurrentSnackBar();
|
||||
OneContext().hideCurrentSnackBar();
|
||||
|
||||
Color backgroundColor;
|
||||
|
||||
// Make some selections based on the "success" value
|
||||
if (success == true) {
|
||||
backgroundColor = Colors.lightGreen;
|
||||
|
||||
// Unspecified icon?
|
||||
if (icon == null) {
|
||||
icon = FontAwesomeIcons.checkCircle;
|
||||
}
|
||||
|
||||
} else if (success == false) {
|
||||
backgroundColor = Colors.deepOrange;
|
||||
|
||||
if (icon == null) {
|
||||
icon = FontAwesomeIcons.timesCircle;
|
||||
}
|
||||
|
||||
// If icon not specified, use the success status
|
||||
if (icon == null) {
|
||||
icon = (success == false) ? FontAwesomeIcons.timesCircle : FontAwesomeIcons.checkCircle;
|
||||
}
|
||||
|
||||
key.currentState.showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
OneContext().showSnackBar(builder: (context) => SnackBar(
|
||||
content: GestureDetector(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(text),
|
||||
Spacer(),
|
||||
FaIcon(icon)
|
||||
]
|
||||
],
|
||||
),
|
||||
)
|
||||
);
|
||||
onTap: onTap,
|
||||
),
|
||||
backgroundColor: backgroundColor,
|
||||
));
|
||||
|
||||
}
|
@ -148,7 +148,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
void _stockUpdateMessage(bool result) {
|
||||
|
||||
showSnackIcon(
|
||||
refreshableKey,
|
||||
result ? "Stock item updated" : "Stock item updated failed",
|
||||
success: result
|
||||
);
|
||||
|
@ -56,7 +56,6 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
||||
);
|
||||
|
||||
showSnackIcon(
|
||||
refreshableKey,
|
||||
success ? "Test result uploaded" : "Could not upload test result",
|
||||
success: success
|
||||
);
|
||||
|
Reference in New Issue
Block a user