2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00
inventree-app/lib/helpers.dart
Oliver aa274b2e45
Stock location scan (#169)
* Add action for scanning a stock location into another location

* Adds barcode scan handler for new functionality

* Handle scanning of stock location

* Cleanup

* Refactor existing barcode scanning functions

- Will require extensive testing and validation

* Add entry to release notes

* Delete dead code

* Improved ordering based on stock quantity

* Bug fix for 'adjustStock' function

* Improve error responses for barcode scanning

* Improve error responses for barcode scanning

* Remove old debug statements

* Add some extra explanatory texts

* Icon change

* Fixes for unit tests

* Adds extra functionality for user profile manager

* Refactor barcode code - do not rely on BuildContext

* Adds initial unit testing for barcode scanning

- Work on mocking barcode data
- Add hooks for testing snackBar and audio files

* Linting fixes

* More barcode unit tests

* Cleanup unit tests for barcode

* Remove unused import

* Handle HTTPException in API

* Improvements for API unit testing

* Unit testing for scanning item into location

* Add unit test for scanning in items from a location context

* Unit test for scanning location into parent location

* Improve feedback for barcode scanning events
2022-07-18 22:10:00 +10:00

76 lines
1.6 KiB
Dart

/*
* A set of helper functions to reduce boilerplate code
*/
/*
* Simplify a numerical value into a string,
* supressing trailing zeroes
*/
import "dart:io";
import "package:audioplayers/audioplayers.dart";
import "package:one_context/one_context.dart";
List<String> debug_messages = [];
void clearDebugMessage() => debug_messages.clear();
int debugMessageCount() => debug_messages.length;
// Check if the debug log contains a given message
bool debugContains(String msg, {bool raiseAssert = true}) {
bool result = false;
for (String element in debug_messages) {
if (element.contains(msg)) {
result = true;
break;
}
}
if (raiseAssert) {
assert(result);
}
return result;
}
/*
* Display a debug message if we are in testing mode, or running in debug mode
*/
void debug(dynamic msg) {
if (Platform.environment.containsKey("FLUTTER_TEST")) {
debug_messages.add(msg.toString());
print("DEBUG: ${msg.toString()}");
}
}
String simpleNumberString(double number) {
// Ref: https://stackoverflow.com/questions/55152175/how-to-remove-trailing-zeros-using-dart
return number.toStringAsFixed(number.truncateToDouble() == number ? 0 : 1);
}
/*
* Play an audio file from the requested path.
*
* Note: If OneContext module fails the 'hasContext' check,
* we will not attempt to play the sound
*/
Future<void> playAudioFile(String path) async {
// Debug message for unit testing
debug("Playing audio file: '${path}'");
if (!OneContext.hasContext) {
return;
}
final player = AudioCache();
player.play(path);
}