首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:无法解析'package:flutter_localizations/flutter_localizations.dart‘中的包'flutter_localizations’

错误:无法解析'package:flutter_localizations/flutter_localizations.dart‘中的包'flutter_localizations’
EN

Stack Overflow用户
提问于 2021-01-14 23:17:33
回答 1查看 3.1K关注 0票数 1

现在我在flutter的应用程序中添加了国际化,这是我在pubspec.yaml中的国际化依赖

代码语言:javascript
运行
复制
intl: ^0.16.1

这是在intl_en.arb中定义的cruiseNavigatorHome

代码语言:javascript
运行
复制
"cruiseNavigatorHome":"Home",
  "@cruiseNavigatorHome":{
    "description": "A description about how to view the source code for this app."
  },

下面是应用程序代码中的获取文本:

代码语言:javascript
运行
复制
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),
  );

但是当我运行这个项目时,给我这个错误:

代码语言:javascript
运行
复制
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.

我应该怎么做才能解决这个问题?我相信这门课就在那儿。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-14 23:53:55

因为答案提供了here,所以您也需要导入flutter_localizations包。

代码语言:javascript
运行
复制
flutter_localizations:
    sdk: flutter
  intl: 0.17.0-nullsafety.2
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65721712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档