diff --git a/lib/api.dart b/lib/api.dart index 4d42be04..34dfb43b 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -16,6 +16,7 @@ import "package:flutter_cache_manager/flutter_cache_manager.dart"; import "package:inventree/widget/dialogs.dart"; import "package:inventree/l10.dart"; +import "package:inventree/helpers.dart"; import "package:inventree/inventree/sentry.dart"; import "package:inventree/inventree/model.dart"; import "package:inventree/user_profile.dart"; diff --git a/lib/helpers.dart b/lib/helpers.dart index 2bdbed53..24dc6e84 100644 --- a/lib/helpers.dart +++ b/lib/helpers.dart @@ -7,9 +7,23 @@ * supressing trailing zeroes */ +import "dart:io"; + import "package:audioplayers/audioplayers.dart"; import "package:one_context/one_context.dart"; + +/* + * 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")) { + print("DEBUG: ${msg.toString()}"); + } +} + + String simpleNumberString(double number) { // Ref: https://stackoverflow.com/questions/55152175/how-to-remove-trailing-zeros-using-dart @@ -19,7 +33,7 @@ String simpleNumberString(double number) { /* * Play an audio file from the requested path. * - * Note: If OneContext module fails the 'hasConext' check, + * Note: If OneContext module fails the 'hasContext' check, * we will not attempt to play the sound */ Future playAudioFile(String path) async { diff --git a/lib/user_profile.dart b/lib/user_profile.dart index 05c98a82..2d4a474c 100644 --- a/lib/user_profile.dart +++ b/lib/user_profile.dart @@ -1,6 +1,7 @@ import "package:sembast/sembast.dart"; +import "package:inventree/helpers.dart"; import "package:inventree/preferences.dart"; class UserProfile { @@ -85,7 +86,7 @@ class UserProfileDBManager { Future addProfile(UserProfile profile) async { if (profile.name.isEmpty || profile.username.isEmpty || profile.password.isEmpty) { - print("Profile missing required values - not adding to database"); + debug("addProfile() : Profile missing required values - not adding to database"); return false; } @@ -93,7 +94,7 @@ class UserProfileDBManager { final bool exists = await profileNameExists(profile.name); if (exists) { - print("UserProfile '${profile.name}' already exists"); + debug("addProfile() : UserProfile '${profile.name}' already exists"); return false; } @@ -120,7 +121,7 @@ class UserProfileDBManager { // Prevent invalid profile data from being updated if (profile.name.isEmpty || profile.username.isEmpty || profile.password.isEmpty) { - print("Profile missing required values - not updating"); + debug("updateProfile() : Profile missing required values - not updating"); return false; } @@ -151,11 +152,11 @@ class UserProfileDBManager { final profiles = await store.find(await _db); - print("getSelectedProfile() - ${profiles.length} profiles available - selected = ${selected}"); + debug("getSelectedProfile() : ${profiles.length} profiles available - selected = ${selected}"); for (int idx = 0; idx < profiles.length; idx++) { - print("- Checking ${idx} - key = ${profiles[idx].key} - ${profiles[idx].value.toString()}"); + debug("- Checking ${idx} - key = ${profiles[idx].key} - ${profiles[idx].value.toString()}"); if (profiles[idx].key is int && profiles[idx].key == selected) { return UserProfile.fromJson(