如何解决此问题 错误:无法解析包?
Posted
技术标签:
【中文标题】如何解决此问题 错误:无法解析包?【英文标题】:How to solve this problem Error: Couldn't resolve the package? 【发布时间】:2021-09-03 01:20:24 【问题描述】:我面临这个问题。我怎么解决这个问题。请帮帮我。
Error: Couldn't resolve the package 'intl' in 'package:intl/intl.dart'.
lib/screens/chat.dart:4:8: Error: Not found: 'package:intl/intl.dart'
import 'package:intl/intl.dart';
^
lib/screens/chat.dart:98:13: Error: 'DateFormat' isn't a type.
final DateFormat date_formatter = DateFormat('yyyy-MM-dd');
^^^^^^^^^^
lib/screens/chat.dart:99:13: Error: 'DateFormat' isn't a type.
final DateFormat time_formatter = DateFormat('hh:ss');
^^^^^^^^^^
lib/screens/chat.dart:98:41: Error: The method 'DateFormat' isn't defined for the class '_
ChatState'.
- '_ChatState' is from 'package:ecommerce_flutter/screens/chat.dart' ('lib/screens
/chat.dart').
Try correcting the name to the name of an existing method, or defining a method named 'Dat
eFormat'.
final DateFormat date_formatter = DateFormat('yyyy-MM-dd');
^^^^^^^^^^
lib/screens/chat.dart:99:41: Error: The method 'DateFormat' isn't defined for the class '_
ChatState'.
- '_ChatState' is from 'package:ecommerce_flutter/screens/chat.dart' ('lib/screens
/chat.dart').
Try correcting the name to the name of an existing method, or defining a method named 'Dat
eFormat'.
final DateFormat time_formatter = DateFormat('hh:ss');
^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie-0.9.10/lib/src/chewie_player.dar
t:83:7: Error: No named parameter with the name 'resizeToAvoidBottomPadding'.
resizeToAvoidBottomPadding: false,
^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart:1466:9: Context: Found thi
s candidate, but the arguments don't match.
const Scaffold(
^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie-0.9.10/lib/src/chewie_player.dar
t:276:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'Bu
ildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie_audio-1.0.0+1/lib/src/chewie_pla
yer.dart:101:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the cl
ass 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieAudioControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_prov
ider.dart:50:59: Error: No named parameter with the name 'nullOk'.
context != null ? Localizations.localeOf(context, nullOk: true) : null,
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found
this candidate, but the arguments don't match.
static Locale localeOf(BuildContext context)
^^^^^^^^
Unhandled exception:
FileSystemE
xception(uri=org-dartlang-untranslatable-uri:package%3Aintl%2Fintl.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_proto
type/standard_file_system.dart:36:7)
#1 asFileUri (package:vm/ker
nel_front_end.dart:599:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:738:21)
<asynchrono
us suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.
dart:562:9)
<asynchronous suspension>
#4 starter (package:flutter_fron
tend_server/server.dart:180:12)
<asynchronous suspension>
#5 main (file:///C:/b
/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:2
4)
<asynchronous suspension>
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to
get more log output. Run with --scan to get full insights.
C:\src\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.1052], locale en-US)
• Flutter version 2.2.2 at C:\src\flutter
• Framework revision d79295af24 (7 days ago), 2021-06-11 08:56:01 -0700
• Engine revision 91c9fc8fe0
• Dart version 2.13.3
[√] android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\mehed\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
[√] VS Code (version 1.57.0)
• VS Code at C:\Users\mehed\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.23.0
[√] Connected device (2 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.101
• Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.48
• No issues found!
Process finished with exit code 0
【问题讨论】:
【参考方案1】:看起来你还没有安装 dart package: intl. 请在此处找到软件包链接:https://pub.dev/packages/intl/install
在您项目的 pubspec.yaml 中添加以下依赖项:
dependencies:
intl: ^0.17.0
详情请查看这里的包安装说明:https://pub.dev/packages/intl/install
【讨论】:
【参考方案2】:1 个月后,我在使用 Equatable 时遇到了这个确切的问题。
有时你的缓存很脏,所以你需要清理:
我们会告诉你每个解决方案:
flutter clean
然后
flutter pub get
我希望它对你有用。对我来说没有:(。
【讨论】:
我也没有。你最终是如何解决这个问题的? @TashPemhiwa 那是很久以前的事了,我什至不记得了,哈哈。但是想一想……我想我有两个包(主应用程序和我为使事情更清洁而创建的子包)。我无法让它在主包上工作,所以我在这个私有子包中导入了 Equatable,导出(使用 export 关键字),在我的主包中,我导入并使用了 equatable来自我自己的子包。这没有任何意义,对吧?相同的平等,相同的版本。但它确实奏效了。 我所做的是这样的: -Main Package -Subpackage ||||子包导入 equatable 并导出它 |||||主包从这个子包中导入 equatable (或你有问题的包)。 有趣。我已经解决了我的问题。但情况不同【参考方案3】:package:intl/intl.dart
确保您的文件在正确的位置
【讨论】:
【参考方案4】:现在我面临这个问题。
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie-0.9.10/lib/src/chewie_player.dar
t:83:7: Error: No named parameter with the name 'resizeToAvoidBottomPadding'.
resizeToAvoidBottomPadding: false,
^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart:1466:9: Context: Found thi
s candidate, but the arguments don't match.
const Scaffold(
^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie-0.9.10/lib/src/chewie_player.dar
t:276:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'Bu
ildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/chewie_audio-1.0.0+1/lib/src/chewie_pla
yer.dart:101:17: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the cl
ass 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/p
ackages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inh
eritFromWidgetOfExactType'.
context.inheritFromWidgetOfExactType(_ChewieAudioControllerProvider)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_prov
ider.dart:50:59: Error: No named parameter with the name 'nullOk'.
context != null ? Localizations.localeOf(context, nullOk: true) : null,
^^^^^^
/C:/src/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found
this candidate, but the arguments don't match.
static Locale localeOf(BuildContext context)
^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to
get more log output. Run with --scan to get full insights.
【讨论】:
您应该为您发现的每个问题创建一个单独的问题。此外,最好描述您尝试过的方法以及您可能有的一些想法,而不是“我有这个问题;解决它”以上是关于如何解决此问题 错误:无法解析包?的主要内容,如果未能解决你的问题,请参考以下文章