v1.0.15 AppText

This commit is contained in:
Tibor Bossanyi 2023-03-19 09:51:05 +01:00
parent cfafdc8994
commit f2f70a6db9
5 changed files with 149 additions and 3 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.15
AppText and translations
Version 1.0.14 Version 1.0.14
OpenAI chat completion extension fix OpenAI chat completion extension fix

30
lib/model/app_text.dart Normal file
View File

@ -0,0 +1,30 @@
import 'dart:collection';
class AppText {
late int textId;
late String textKey;
HashMap<String, String> translations = HashMap();
AppText.fromJson(Map json) {
textId = json['textId'];
textKey = json['textKey'];
if (json['translations'] != null && json['translations'].length > 0) {
json['translations'].forEach((translation) {
translations[translation['languageCode']] = translation['translation'];
});
}
}
Map<String, dynamic> toJson() => {
"textId": textId,
"textKey": textKey,
"translations": translations.toString(),
};
@override
String toString() {
return toJson().toString();
}
}

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.14 version: 1.0.15
environment: environment:
sdk: ">=2.18.6 <3.0.0" sdk: ">=2.18.6 <3.0.0"

115
test/app_text_test.dart Normal file
View File

@ -0,0 +1,115 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:workouttest_util/model/app_text.dart';
main() {
late String appTextJson;
setUp(() {
appTextJson = '''
[
{
"textId": 1,
"textKey": "monday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 1,
"languageCode": "hu",
"translation": "hétfő"
}
]
},
{
"textId": 2,
"textKey": "tuesday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 2,
"languageCode": "hu",
"translation": "kedd"
}
]
},
{
"textId": 3,
"textKey": "wednesday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 3,
"languageCode": "hu",
"translation": "szerda"
}
]
},
{
"textId": 4,
"textKey": "thursday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 4,
"languageCode": "hu",
"translation": "csütörtök"
}
]
},
{
"textId": 5,
"textKey": "friday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 5,
"languageCode": "hu",
"translation": "péntek"
}
]
},
{
"textId": 6,
"textKey": "saturday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 6,
"languageCode": "hu",
"translation": "szombat"
}
]
},
{
"textId": 7,
"textKey": "sunday",
"screenshotUrl": null,
"checked": false,
"translations": [
{
"translationId": 7,
"languageCode": "hu",
"translation": "vasárnap"
}
]
}
]
''';
});
group('customer', () {
test('decode from json successful', () async {
Iterable json = jsonDecode(appTextJson);
final List<AppText> appTexts = json.map((text) => AppText.fromJson(text)).toList();
expect(appTexts[0].textKey, "monday");
expect(appTexts[1].translations['hu'], "kedd");
print(appTexts[0]);
});
});
}

View File

@ -5,8 +5,6 @@ import 'package:workouttest_util/model/cache.dart';
import 'package:workouttest_util/model/customer.dart'; import 'package:workouttest_util/model/customer.dart';
import 'package:workouttest_util/model/property.dart'; import 'package:workouttest_util/model/property.dart';
import 'package:workouttest_util/repository/customer_repository.dart'; import 'package:workouttest_util/repository/customer_repository.dart';
import 'dart:collection';
import 'package:intl/intl.dart';
main() { main() {
setUp(() { setUp(() {