Reputation: 38631
Now I am add international in my apps of flutter, this is my international dependencies in pubspec.yaml
:
intl: ^0.16.1
and this is the cruiseNavigatorHome
define in intl_en.arb
:
"cruiseNavigatorHome":"Home",
"@cruiseNavigatorHome":{
"description": "A description about how to view the source code for this app."
},
and this is the getting text in the apps code:
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),
);
but when I run this project, give me this error:
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.
what should I do to fix this problem? I am sure the class is right there.
Upvotes: 5
Views: 15478
Reputation: 4387
The issue is adding flutter_localizations package has very unexpected syntax. Provided official example confuses everyone as noone expect it that way inside pubspec.yaml. Like this:
flutter_localizations:
sdk: flutter
And yes now pubspec.yaml file will have something like this (repeating sdk: flutter texts):
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
Plus you will need intl package:
intl: ^0.17.0
Official guide here
Upvotes: 3