现在我在flutter的应用程序中添加了国际化,这是我在pubspec.yaml
中的国际化依赖
intl: ^0.16.1
这是在intl_en.arb
中定义的cruiseNavigatorHome
"cruiseNavigatorHome":"Home",
"@cruiseNavigatorHome":{
"description": "A description about how to view the source code for this app."
},
下面是应用程序代码中的获取文本:
import 'package:flutter_gen/gen_l10n/cruise_localizations.dart';
return Scaffold(
body: viewService.buildComponent("homelist"),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label:CruiseLocalizations.of(context).cruiseNavigatorHome),
BottomNavigationBarItem(icon: Icon(Icons.follow_the_signs), label: '关注'),
BottomNavigationBarItem(icon: Icon(Icons.rss_feed), label: '频道'),
BottomNavigationBarItem(icon: Icon(Icons.school), label: '我的'),
],
currentIndex: state.selectIndex,
fixedColor: Colors.blue,
onTap: _onItemTapped,
unselectedItemColor: Color(0xff666666),
type: BottomNavigationBarType.fixed),
);
但是当我运行这个项目时,给我这个错误:
Error: Could not resolve the package 'flutter_localizations' in 'package:flutter_localizations/flutter_localizations.dart'.
.dart_tool/flutter_gen/gen_l10n/cruise_localizations.dart:7:8: Error: Not found: 'package:flutter_localizations/flutter_localizations.dart'
import 'package:flutter_localizations/flutter_localizations.dart';
^
.dart_tool/flutter_gen/gen_l10n/cruise_localizations.dart:162:5: Error: Getter not found: 'GlobalMaterialLocalizations'.
GlobalMaterialLocalizations.delegate,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.dart_tool/flutter_gen/gen_l10n/cruise_localizations.dart:163:5: Error: Getter not found: 'GlobalCupertinoLocalizations'.
GlobalCupertinoLocalizations.delegate,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.dart_tool/flutter_gen/gen_l10n/cruise_localizations.dart:164:5: Error: Getter not found: 'GlobalWidgetsLocalizations'.
GlobalWidgetsLocalizations.delegate,
^^^^^^^^^^^^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Aflutter_localizations%2Fflutter_localizations.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:32:7)
#1 asFileUri (package:vm/kernel_front_end.dart:599:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:738:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:554:9)
<asynchronous suspension>
#4 starter (package:flutter_frontend_server/server.dart:180:12)
<asynchronous suspension>
#5 main (file:///opt/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:24)
<asynchronous suspension>
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro.
我应该怎么做才能解决这个问题?我相信这门课就在那儿。
发布于 2021-01-14 23:53:55
因为答案提供了here,所以您也需要导入flutter_localizations
包。
flutter_localizations:
sdk: flutter
intl: 0.17.0-nullsafety.2
https://stackoverflow.com/questions/65721712
复制相似问题