Aitrainer_app 1.1.1

test menu, customer modification, exercise save images, localization
This commit is contained in:
Bossanyi Tibor
2020-07-07 16:53:03 +02:00
parent 79142b92f2
commit 2177db10ea
80 changed files with 2751 additions and 553 deletions
+55
View File
@@ -0,0 +1,55 @@
import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AppLanguage extends ChangeNotifier {
static final AppLanguage _singleton = AppLanguage._internal();
Locale _appLocale = Locale('en');
factory AppLanguage() {
return _singleton;
}
AppLanguage._internal();
static Future<AppLanguage> getInstance() async {
return _singleton;
}
Locale get appLocal => _appLocale ?? Locale("en");
fetchLocale() async {
var prefs = await SharedPreferences.getInstance();
if (prefs.getString('language_code') == null) {
_appLocale = Locale('en');
}
_appLocale = Locale(prefs.getString('language_code'));
print(" ---- Fetched lang: " + _appLocale.toString());
}
getLocale(SharedPreferences prefs) {
if (prefs.getString('language_code') == null) {
_appLocale = Locale('en');
}
_appLocale = Locale(prefs.getString('language_code'));
}
void changeLanguage(Locale type) async {
var prefs = await SharedPreferences.getInstance();
if (_appLocale == type) {
return;
}
if (type == Locale("hu")) {
_appLocale = Locale("hu");
await prefs.setString('language_code', 'hu');
await prefs.setString('countryCode', 'HU');
} else {
_appLocale = Locale("en");
await prefs.setString('language_code', 'en');
await prefs.setString('countryCode', 'US');
}
print(" ---- Stored lang: " + _appLocale.toString());
notifyListeners();
}
}
+70
View File
@@ -0,0 +1,70 @@
import 'dart:convert';
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
class AppLocalizations {
Locale locale;
AppLocalizations(this.locale);
// Helper method to keep the code in the widgets concise
// Localizations are accessed using an InheritedWidget "of" syntax
static AppLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
// Static member to have a simple access to the delegate from the MaterialApp
static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
Map<String, String> _localizedStrings;
setLocale(Locale locale) {
this.locale = locale;
}
Future<bool> load() async {
// Load the language JSON file from the "lang" folder
String jsonString =
await rootBundle.loadString('i18n/${locale.languageCode}.json');
Map<String, dynamic> jsonMap = json.decode(jsonString);
_localizedStrings = jsonMap.map((key, value) {
return MapEntry(key, value.toString());
});
return true;
}
// This method will be called from every widget which needs a localized text
String translate(String key) {
return _localizedStrings[key];
}
}
class _AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
// This delegate instance will never change (it doesn't even have fields!)
// It can provide a constant constructor.
const _AppLocalizationsDelegate();
@override
bool isSupported(Locale locale) {
// Include all of your supported language codes here
return ['en', 'hu'].contains(locale.languageCode);
}
@override
Future<AppLocalizations> load(Locale locale) async {
// AppLocalizations class is where the JSON loading actually runs
AppLocalizations localizations = new AppLocalizations(locale);
await localizations.load();
return localizations;
}
@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
}