wt1.1a flutter_bloc

This commit is contained in:
Bossanyi Tibor
2020-08-17 12:38:47 +02:00
parent 8363d7772f
commit ac1c6be8f3
90 changed files with 4281 additions and 2854 deletions
+19 -7
View File
@@ -6,8 +6,9 @@ import 'package:flutter/services.dart';
class AppLocalizations {
Locale locale;
bool isTest;
AppLocalizations(this.locale);
AppLocalizations(this.locale, {this.isTest = false});
// Helper method to keep the code in the widgets concise
// Localizations are accessed using an InheritedWidget "of" syntax
@@ -17,7 +18,7 @@ class AppLocalizations {
// Static member to have a simple access to the delegate from the MaterialApp
static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
AppLocalizationsDelegate();
Map<String, String> _localizedStrings;
@@ -38,18 +39,24 @@ class AppLocalizations {
return true;
}
Future<AppLocalizations> loadTest(Locale locale) async {
return AppLocalizations(locale);
}
// This method will be called from every widget which needs a localized text
String translate(String key) {
if (isTest) return key;
return _localizedStrings[key];
}
}
class _AppLocalizationsDelegate
class AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
final bool isTest;
// This delegate instance will never change (it doesn't even have fields!)
// It can provide a constant constructor.
const _AppLocalizationsDelegate();
const AppLocalizationsDelegate({this.isTest = false});
@override
bool isSupported(Locale locale) {
@@ -60,11 +67,16 @@ class _AppLocalizationsDelegate
@override
Future<AppLocalizations> load(Locale locale) async {
// AppLocalizations class is where the JSON loading actually runs
AppLocalizations localizations = new AppLocalizations(locale);
await localizations.load();
AppLocalizations localizations = new AppLocalizations(locale, isTest: this.isTest);
if (isTest) {
await localizations.loadTest(locale);
} else {
await localizations.load();
}
return localizations;
}
@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
bool shouldReload(AppLocalizationsDelegate old) => false;
}