警告:此应用程序的区域设置(en.json_US)并非受其所有本地化委托的支持



本地化新手,我刚刚在我的应用程序上完成了它的实现,它甚至不读英语,当我运行我的应用程序时,它给了我这个错误,请注意,我还没有使用本地化在我的应用程序中表示,还没有使用用于选择语言的按钮......我做错了什么?

这是我的代码

MaterialApp(
locale: _locale,
supportedLocales: [
Locale('en.json', 'US'),
Locale('ar', ''),
Locale('ar', 'IQ'),
],
localizationsDelegates: [
DemoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
localeResolutionCallback: (deviceLocale, supportedLocales) {
for (var locale in supportedLocales) {
if (locale.languageCode == deviceLocale.languageCode &&
locale.countryCode == deviceLocale.countryCode) {
return deviceLocale;
}
}
return supportedLocales.first;
},
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Color(0xffba0100),
accentColor: Color(0xff188949),
canvasColor: Colors.grey[100],
textTheme: TextTheme().copyWith(
bodyText1: TextStyle(
color: Colors.white,
fontSize: 17.0,
fontWeight: FontWeight.w700,
),
bodyText2: TextStyle(
color: Colors.white,
),
headline6: TextStyle(
color: Colors.black,
fontSize: 18.0,
),
)),
title: 'Tamata Online',
initialRoute: '/',
routes: {
'/': (ctx) => LoadingScreen(
initScreen), //TODO put it back to be LoadingScreen(initScreen)
TabsScreen.id: (ctx) => TabsScreen(
filteredBySearch: filteredBySearch,
filteredBySpecialSearch: filteredBySpecialSearch,
),
SettingsScreen.id: (ctx) => SettingsScreen(),
CartScreen.id: (ctx) => CartScreen(),
IntroScreen.id: (ctx) => IntroScreen(),
ChooseLanguageScreen.id: (ctx) => ChooseLanguageScreen(),
SpecialOffers.id: (ctx) => SpecialOffers(),
},
)

这是我的演示本地化和代表:

import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class DemoLocalizations {
final Locale locale;
DemoLocalizations(this.locale);
static DemoLocalizations of(BuildContext context) {
return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
}
Map<String, String> _localizedValues;
Future load() async {
String jsonStringValues =
await rootBundle.loadString('assets/languages/${locale.languageCode}');
Map<String, dynamic> mappedJson = jsonDecode(jsonStringValues);
_localizedValues =
mappedJson.map((key, value) => MapEntry(key, value.toString()));
}
String getTranslatedValue(String key) {
return _localizedValues[key];
}
static const LocalizationsDelegate<DemoLocalizations> delegate =
_DemoLocalizationDelegate();
}
class _DemoLocalizationDelegate
extends LocalizationsDelegate<DemoLocalizations> {
const _DemoLocalizationDelegate();
@override
bool isSupported(Locale locale) {
return ['en', 'ar', 'ar'].contains(locale.languageCode);
}
@override
Future<DemoLocalizations> load(Locale locale) async {
DemoLocalizations localization = DemoLocalizations(locale);
await localization.load();
return localization;
}
@override
bool shouldReload(_DemoLocalizationDelegate old) => false;
}

更改

supportedLocales: [
Locale('en.json', 'US'),
Locale('ar', ''),
Locale('ar', 'IQ'),
],

supportedLocales: [
Locale('en', 'US'),
Locale('ar', ''),
Locale('ar', 'IQ'),
],

在支持的Locales中,将en.json更改为en。

最新更新