我想将tr标签添加到Flutter本地化部分。我是 尽管有支持Tr的错误。错误是 跟随;错误:元素类型为'Locale(其中Locale在 C:\ Users \ StatTark \ AppData \ Roaming \ Pub \ Cache \ hosted \ pub.dartlang.org \ intl-0.16.1 \ lib \ src \ locale.dart)' 不能分配给列表类型'区域设置(其中区域设置在 C:\ flutter \ bin \ cache \ pkg \ sky_engine \ lib \ ui \ window.dart)'。
错误:无法实例化抽象类。 (位于[ajanda] lib \ pages \ mainmenu.dart:36的instantiate_abstract_class)
我不知道我是否在使用中犯了一个错误,如果您能提供帮助,我会很高兴。
class MainMenu extends StatelessWidget {
MainMenu({Key key}) : super(key: key);
final _sdb = SettingsDbHelper();
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _sdb.getSettings(),
builder: (context, snapshot) {
if (snapshot.data == null) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: [Locale('en','US'),Locale('tr','')], //The error is here
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Text(proTranslate["Yükleniyor....."][Language.languageIndex]),
),
),
);
} else {
Language.languageIndex = snapshot.data[0].language;
return DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness) => ThemeData(
brightness: brightness,
fontFamily: snapshot.data[0].fontName,
floatingActionButtonTheme: FloatingActionButtonThemeData(
foregroundColor: Colors.green,
),
),
themedWidgetBuilder: (context, theme) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: [Locale('en','US'),Locale('tr','')],
debugShowCheckedModeBanner: false,
theme: theme,
home: MainMenuBody(
warning: snapshot.data[0].warning,
),
// navigatorKey: navigatorKey,
);
});
}
},
);
}
}
class MainMenuBody extends StatefulWidget {....}
答案 0 :(得分:0)
您可以尝试/测试的一些建议,请参见下文。
将[Locale('en','US'),Locale('tr','')],
替换为[Locale('en'),Locale('tr')],
首先初始化受支持的语言环境列表,并相应地使用它。
// init before build
final List<Locale> appSupportedLocales = [
Locale('en'),
Locale('tr')
];
// ...
// then use it like this
supportedLocales: appSupportedLocales,