mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 10:45:29 +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/dialogs.dart';
|
||||||
|
import 'package:InvenTree/widget/snacks.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.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';
|
import 'package:qr_code_scanner/qr_code_scanner.dart';
|
||||||
|
|
||||||
@ -139,6 +141,19 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) {
|
Future<void> onBarcodeUnknown(Map<String, dynamic> data) {
|
||||||
|
|
||||||
|
showSnackIcon(
|
||||||
|
"No barcode",
|
||||||
|
icon: FontAwesomeIcons.exclamationCircle,
|
||||||
|
onTap: () {
|
||||||
|
print("Tappity");
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
_controller.resumeCamera();
|
||||||
|
|
||||||
|
/*
|
||||||
showErrorDialog(
|
showErrorDialog(
|
||||||
_context,
|
_context,
|
||||||
data['error'] ?? '',
|
data['error'] ?? '',
|
||||||
@ -149,6 +164,8 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
_controller.resumeCamera();
|
_controller.resumeCamera();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -385,14 +402,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
|||||||
@override
|
@override
|
||||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
|
||||||
// If the barcode points to a 'stocklocation', great!
|
// If the barcode points to a 'stocklocation', great!
|
||||||
if (!data.containsKey('stocklocation')) {
|
if (data.containsKey('stocklocation')) {
|
||||||
showErrorDialog(
|
|
||||||
_context,
|
|
||||||
"Invalid Barcode",
|
|
||||||
"Barcode does not match a Stock Location",
|
|
||||||
onDismissed: _controller.resumeCamera,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Extract location information
|
// Extract location information
|
||||||
int location = data['stocklocation']['pk'] as int;
|
int location = data['stocklocation']['pk'] as int;
|
||||||
|
|
||||||
@ -402,11 +412,35 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler {
|
|||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
Navigator.of(_context).pop();
|
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 {
|
Future<void> scanQrCode(BuildContext context) async {
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView(BarcodeScanHandler())));
|
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);
|
final bool result = await part.update(context, values: values);
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
refreshableKey,
|
|
||||||
result ? "Part edited" : "Part editing failed",
|
result ? "Part edited" : "Part editing failed",
|
||||||
success: result
|
success: result
|
||||||
);
|
);
|
||||||
|
@ -11,26 +11,44 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.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
|
OneContext().hideCurrentSnackBar();
|
||||||
key.currentState.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(
|
OneContext().showSnackBar(builder: (context) => SnackBar(
|
||||||
SnackBar(
|
content: GestureDetector(
|
||||||
content: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(text),
|
Text(text),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
FaIcon(icon)
|
FaIcon(icon)
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
)
|
onTap: onTap,
|
||||||
);
|
),
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
));
|
||||||
|
|
||||||
}
|
}
|
@ -148,7 +148,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
void _stockUpdateMessage(bool result) {
|
void _stockUpdateMessage(bool result) {
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
refreshableKey,
|
|
||||||
result ? "Stock item updated" : "Stock item updated failed",
|
result ? "Stock item updated" : "Stock item updated failed",
|
||||||
success: result
|
success: result
|
||||||
);
|
);
|
||||||
|
@ -56,7 +56,6 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
);
|
);
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
refreshableKey,
|
|
||||||
success ? "Test result uploaded" : "Could not upload test result",
|
success ? "Test result uploaded" : "Could not upload test result",
|
||||||
success: success
|
success: success
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user