I am new in flutter, i am trying to localize languages, but getting error
localizationsDelegates: <LocalizationsDelegate>[
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
EasyLocalizationDelegate(
locale: data.locale ?? Locale('en', 'US'),
path: 'resources/langs',
),
],
supportedLocales: <Locale>[
const Locale("en", "US"),
const Locale("ar", "AR"),
],
getting error The method 'tr' was called on null. Receiver: null Tried calling: tr("Click here to continue")
in the line in basescreen file
Text(
AppLocalizations.of(context).tr('Click here to continue'),
// "Click here to continue",
style: _textStyle,
),
my load functin is
Future<bool> load() async {
// Load the language JSON file from the "lang" folder
developer.log('file name', name: 'lang/${locale.languageCode}.json');
String jsonString =
await rootBundle.loadString('lang/${locale.languageCode}.json');
//await rootBundle.loadString('lang/${locale.languageCode}-${locale.countryCode}.json');
developer.log('file text', name: jsonString);
Map<String, dynamic> jsonMap = json.decode(jsonString);
_localizedStrings = jsonMap.map((key, value) {
return MapEntry(key, value.toString());
});
return true;
}
i have also added the blow code in my pubspec.yaml asset
- lang/
- resources/langs/en-US.json
- resources/langs/ar-AR.json