v1.0.3 webapi client
This commit is contained in:
+11
-11
@@ -7,7 +7,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
class AppLanguage with Logging {
|
||||
static final AppLanguage _singleton = AppLanguage._internal();
|
||||
|
||||
Locale? _appLocale = Locale('en');
|
||||
Locale? _appLocale = const Locale('en');
|
||||
|
||||
factory AppLanguage() {
|
||||
return _singleton;
|
||||
@@ -19,18 +19,18 @@ class AppLanguage with Logging {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
Locale get appLocal => _appLocale ?? Locale("en");
|
||||
Locale get appLocal => _appLocale ?? const Locale("en");
|
||||
|
||||
Future<void> fetchLocale() async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
String? langCode = prefs.getString('language_code');
|
||||
log(" ---- lang code $langCode");
|
||||
if (langCode == null) {
|
||||
_appLocale = Locale('en');
|
||||
_appLocale = const Locale('en');
|
||||
} else {
|
||||
_appLocale = Locale(langCode);
|
||||
}
|
||||
log(" ---- Fetched lang: " + _appLocale.toString());
|
||||
log(" ---- Fetched lang: $_appLocale");
|
||||
}
|
||||
|
||||
getLocale(SharedPreferences prefs) {
|
||||
@@ -38,15 +38,15 @@ class AppLanguage with Logging {
|
||||
if (langCode == null) {
|
||||
final String localName = Platform.localeName;
|
||||
if (localName.endsWith("HU")) {
|
||||
_appLocale = Locale('hu');
|
||||
_appLocale = const Locale('hu');
|
||||
langCode = "hu";
|
||||
} else {
|
||||
_appLocale = Locale('en');
|
||||
_appLocale = const Locale('en');
|
||||
langCode = "en";
|
||||
}
|
||||
}
|
||||
_appLocale = Locale(langCode);
|
||||
log(" ---- Get lang: " + _appLocale.toString() + " lang code $langCode");
|
||||
log(" ---- Get lang: $_appLocale lang code $langCode");
|
||||
}
|
||||
|
||||
void changeLanguage(Locale type) async {
|
||||
@@ -54,15 +54,15 @@ class AppLanguage with Logging {
|
||||
if (_appLocale == type) {
|
||||
return;
|
||||
}
|
||||
if (type == Locale("hu")) {
|
||||
_appLocale = Locale("hu");
|
||||
if (type == const Locale("hu")) {
|
||||
_appLocale = const Locale("hu");
|
||||
await prefs.setString('language_code', 'hu');
|
||||
await prefs.setString('countryCode', 'HU');
|
||||
} else {
|
||||
_appLocale = Locale("en");
|
||||
_appLocale = const Locale("en");
|
||||
await prefs.setString('language_code', 'en');
|
||||
await prefs.setString('countryCode', 'US');
|
||||
}
|
||||
log(" ---- Stored lang: " + _appLocale.toString());
|
||||
log(" ---- Stored lang: $_appLocale");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class AppLocalizations with Logging {
|
||||
|
||||
Future<bool> load() async {
|
||||
// Load the language JSON file from the "lang" folder
|
||||
log(" -- load language pieces " + locale.languageCode);
|
||||
log(" -- load language pieces ${locale.languageCode}");
|
||||
String jsonString = await rootBundle.loadString('i18n/${locale.languageCode}.json');
|
||||
Map<String, dynamic> jsonMap = json.decode(jsonString);
|
||||
|
||||
@@ -45,7 +45,7 @@ class AppLocalizations with Logging {
|
||||
String translate(String key) {
|
||||
if (isTest) return key;
|
||||
String? translated = _localizedStrings[key];
|
||||
return translated != null ? translated : key;
|
||||
return translated ?? key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
@override
|
||||
Future<AppLocalizations> load(Locale locale) async {
|
||||
// AppLocalizations class is where the JSON loading actually runs
|
||||
AppLocalizations localizations = new AppLocalizations(locale, isTest: this.isTest);
|
||||
AppLocalizations localizations = AppLocalizations(locale, isTest: isTest);
|
||||
if (isTest) {
|
||||
await localizations.loadTest(locale);
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
import 'package:workouttest_util/util/app_language.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DateRate {
|
||||
|
||||
+24
-24
@@ -3,8 +3,8 @@ import 'package:workouttest_util/util/string_extension.dart';
|
||||
enum LoginType { email, fb, google, apple }
|
||||
|
||||
extension LoginTypeExt on LoginType {
|
||||
bool equalsTo(LoginType type) => this.toString() == type.toString();
|
||||
bool equalsStringTo(String type) => this.toString() == type;
|
||||
bool equalsTo(LoginType type) => toString() == type.toString();
|
||||
bool equalsStringTo(String type) => toString() == type;
|
||||
}
|
||||
|
||||
enum TrackingEvent {
|
||||
@@ -69,60 +69,60 @@ T enumFromString<T>(Iterable<T> values, String value) {
|
||||
}
|
||||
|
||||
extension TrackingEventExt on TrackingEvent {
|
||||
String enumToString() => this.toString().split(".").last;
|
||||
String enumToString() => toString().split(".").last;
|
||||
|
||||
bool equalsTo(TrackingEvent event) => this.toString() == event.toString();
|
||||
bool equalsStringTo(String event) => this.toString() == event;
|
||||
bool equalsTo(TrackingEvent event) => toString() == event.toString();
|
||||
bool equalsStringTo(String event) => toString() == event;
|
||||
}
|
||||
|
||||
enum PropertyEnum { Ectomorph, Mesomorph, Endomorph }
|
||||
|
||||
extension PropertyExt on PropertyEnum {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
String toStr() => toString().split(".").last;
|
||||
|
||||
bool equalsTo(PropertyEnum event) => this.toString() == event.toString();
|
||||
bool equalsStringTo(String event) => this.toString() == event;
|
||||
bool equalsTo(PropertyEnum event) => toString() == event.toString();
|
||||
bool equalsStringTo(String event) => toString() == event;
|
||||
}
|
||||
|
||||
enum SizesEnum { Weight, Height, Shoulder, Neck, Biceps, Chest, Belly, Hip, ThighTop, ThighMiddle, Knee, Calf, Ankle, Underarm, Lowerarm }
|
||||
|
||||
extension SizesExt on SizesEnum {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(SizesEnum event) => this.toString() == event.toString();
|
||||
bool equalsStringTo(String event) => this.toString() == event;
|
||||
String toStr() => toString().split(".").last;
|
||||
bool equalsTo(SizesEnum event) => toString() == event.toString();
|
||||
bool equalsStringTo(String event) => toString() == event;
|
||||
}
|
||||
|
||||
enum EvaluationText { very_poor, poor, fair, below_average, average, above_average, good, excellent, elite }
|
||||
|
||||
extension EvaluationTextExt on EvaluationText {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(EvaluationText eval) => this.toString() == eval.toString();
|
||||
bool equalsStringTo(String eval) => this.toStr() == eval;
|
||||
String toStr() => toString().split(".").last;
|
||||
bool equalsTo(EvaluationText eval) => toString() == eval.toString();
|
||||
bool equalsStringTo(String eval) => toStr() == eval;
|
||||
}
|
||||
|
||||
enum ExerciseTypeTrainingPlanState { none, added, executed }
|
||||
|
||||
extension ExerciseTypeTrainingPlanStateExt on ExerciseTypeTrainingPlanState {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(ExerciseTypeTrainingPlanState state) => this.toString() == state.toString();
|
||||
bool equalsStringTo(String state) => this.toStr() == state;
|
||||
String toStr() => toString().split(".").last;
|
||||
bool equalsTo(ExerciseTypeTrainingPlanState state) => toString() == state.toString();
|
||||
bool equalsStringTo(String state) => toStr() == state;
|
||||
}
|
||||
|
||||
enum ExerciseSaveType { test, training, test_set }
|
||||
|
||||
extension ExerciseSaveTypeExt on ExerciseSaveType {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
bool equalsTo(ExerciseSaveType type) => this.toString() == type.toString();
|
||||
bool equalsStringTo(String type) => this.toStr() == type;
|
||||
String toStr() => toString().split(".").last;
|
||||
bool equalsTo(ExerciseSaveType type) => toString() == type.toString();
|
||||
bool equalsStringTo(String type) => toStr() == type;
|
||||
}
|
||||
|
||||
enum MuscleGroup { chest, biceps, triceps, back, shoulders, core, thigh, calf }
|
||||
|
||||
extension MuscleGroupExt on MuscleGroup {
|
||||
String toStr() => this.toString().split(".").last;
|
||||
String toText() => this.toString().split(".").last.capitalize();
|
||||
bool equalsTo(MuscleGroup type) => this.toString() == type.toString();
|
||||
bool equalsStringTo(String type) => this.toStr() == type;
|
||||
String toStr() => toString().split(".").last;
|
||||
String toText() => toString().split(".").last.capitalize();
|
||||
bool equalsTo(MuscleGroup type) => toString() == type.toString();
|
||||
bool equalsStringTo(String type) => toStr() == type;
|
||||
String getStrByIndex(int index) => MuscleGroup.values.elementAt(index).toStr();
|
||||
MuscleGroup getByIndex(int index) => MuscleGroup.values.elementAt(index);
|
||||
String getTextByIndex(int index) => MuscleGroup.values.elementAt(index).toText();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
extension StringExtension on String {
|
||||
String capitalize() {
|
||||
return "${this[0].toUpperCase()}${this.substring(1).toLowerCase()}";
|
||||
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user