v1.0.19 dotenv logging test

This commit is contained in:
Tibor Bossanyi 2023-03-28 08:24:17 +02:00
parent 7a27a89397
commit dbb3b5005d
5 changed files with 32 additions and 41 deletions

View File

@ -1,5 +1,8 @@
Workout Test and Diet 4 You Common Util Functions Workout Test and Diet 4 You Common Util Functions
Version 1.0.19
dotenv logging test
Version 1.0.18 Version 1.0.18
debug by dotenv debug by dotenv

2
assets/.env Normal file
View File

@ -0,0 +1,2 @@
dotenv=1
debug=2

View File

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
// ignore: depend_on_referenced_packages // ignore: depend_on_referenced_packages
@ -8,11 +6,11 @@ import 'package:intl/intl.dart';
mixin Logging { mixin Logging {
void log(String message) { void log(String message) {
String debug = dotenv.get("debug", fallback: "0"); String debug = dotenv.get("debug", fallback: "0");
String? platformDebug = Platform.environment['debug'];
if (debug == "2") { if (debug == "2") {
print("Debug-mode: $kDebugMode, dotenv: $debug, platform: $platformDebug"); print("Debug-mode: $kDebugMode, dotenv: $debug");
} }
if (kDebugMode || debug == "1" || platformDebug == "1") { if (kDebugMode || debug == "1" || debug == "2") {
DateTime time = DateTime.now(); DateTime time = DateTime.now();
print(DateFormat('yyyy-MM-dd HH:mm:ss ').format(time) + message); print(DateFormat('yyyy-MM-dd HH:mm:ss ').format(time) + message);
} }

View File

@ -1,6 +1,6 @@
name: workouttest_util name: workouttest_util
description: Workout Test app and web functions. description: Workout Test app and web functions.
version: 1.0.18 version: 1.0.19
environment: environment:
sdk: ">=2.18.6 <3.0.0" sdk: ">=2.18.6 <3.0.0"
@ -44,39 +44,6 @@ dev_dependencies:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter: flutter:
assets:
# To add assets to your package, add an assets section, like this: - assets/.env
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages

21
test/logging_test.dart Normal file
View File

@ -0,0 +1,21 @@
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:workouttest_util/util/logging.dart';
class LoggingTest with Logging {}
main() {
late LoggingTest mockLogging;
setUp(() async {
mockLogging = LoggingTest();
await dotenv.load(fileName: "assets/.env");
});
group('logging', () {
test('test dotenv', () {
String debug = dotenv.get("debug", fallback: "1");
mockLogging.log("message");
expect(debug, "2");
});
});
}