Flutter:如何解决系统找不到指定的路径
Posted
技术标签:
【中文标题】Flutter:如何解决系统找不到指定的路径【英文标题】:Flutter:How to solve system can not find the path Specified 【发布时间】:2021-05-30 13:20:11 【问题描述】:我一直在开发一个 Flutter 应用,最近安装了三个与 firebase 相关的 pacakges firebase_core、cloud_firestore 和 firebase_storage。但安装后,当我尝试将它们导入 .dart 文件时,我面临“系统找不到指定的路径”
导入'包:quiver/core.dart';'错误。那我该怎么办,这是我的 pubspec.yaml 文件。如果可以修复错误,我什至尝试将 quiver 添加到 pubspec.yaml,但它没有。
name: bookecommerceapp
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In ios, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.22.6
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
google_fonts: any
http: ^0.12.2
provider: ^4.3.3
search_page: ^1.4.0
loading: ^1.0.2
file_picker: ^2.1.6
firebase_core: ^0.7.0
cloud_firestore: ^0.16.0+1
firebase_storage: ^7.0.0
quiver: ^2.1.5
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- images/
- google_fonts/
# - imagesa_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
fonts:
- family: OpenSans
fonts:
- asset: google_fonts/OpenSans-Bold.ttf
- asset: google_fonts/OpenSans-Bolditalic.ttf
- asset: google_fonts/OpenSans-ExtraBold.ttf
- asset: google_fonts/OpenSans-ExtraBoldItalic.ttf
- asset: google_fonts/OpenSans-Light.ttf
- asset: google_fonts/OpenSans-Regular.ttf
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
这是我的完整错误堆栈跟踪
Performing hot reload...
Syncing files to device Android SDK built for x86...
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/firebase_storage.dart:11:8: Error: Error when reading '/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.5/lib/core.dart': The system cannot find the path specified.
import 'package:quiver/core.dart';
^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.7.0/lib/firebase_core.dart:10:8: Error: Error when reading '/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.5/lib/core.dart': The system cannot find the path specified.
import 'package:quiver/core.dart';
^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/firebase_core_platform_interface.dart:15:8: Error: Error when reading '/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.5/lib/core.dart': The system cannot find the path specified.
import 'package:quiver/core.dart';
^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/src/firebase_storage.dart:168:23: Error: The method 'hash2' isn't defined for the class 'FirebaseStorage'.
- 'FirebaseStorage' is from 'package:firebase_storage/firebase_storage.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/firebase_storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash2'.
int get hashCode => hash2(app.name, bucket);
^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/src/reference.dart:211:23: Error: The method 'hash2' isn't defined for the class 'Reference'.
- 'Reference' is from 'package:firebase_storage/firebase_storage.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/firebase_storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash2'.
int get hashCode => hash2(storage, fullPath);
^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/src/task_snapshot.dart:49:23: Error: The method 'hash2' isn't defined for the class 'TaskSnapshot'.
- 'TaskSnapshot' is from 'package:firebase_storage/firebase_storage.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_storage-7.0.0/lib/firebase_storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash2'.
int get hashCode => hash2(storage, ref);
^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.7.0/lib/src/firebase_app.dart:65:23: Error: The method 'hash2' isn't defined for the class 'FirebaseApp'.
- 'FirebaseApp' is from 'package:firebase_core/firebase_core.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.7.0/lib/firebase_core.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash2'.
int get hashCode => hash2(name, options);
^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/src/firebase_exception.dart:63:12: Error: The method 'hash3' isn't defined for the class 'FirebaseException'.
- 'FirebaseException' is from 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/firebase_core_platform_interface.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash3'.
return hash3(plugin, code, message);
^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/src/firebase_options.dart:183:12: Error: The method 'hashObjects' isn't defined for the class 'FirebaseOptions'.
- 'FirebaseOptions' is from 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/firebase_core_platform_interface.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashObjects'.
return hashObjects(asMap.entries);
^^^^^^^^^^^
/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/src/platform_interface/platform_interface_firebase_app.dart:64:23: Error: The method 'hash2' isn't defined for the class 'FirebaseAppPlatform'.
- 'FirebaseAppPlatform' is from 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart' ('/C:/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-3.0.1/lib/firebase_core_platform_interface.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hash2'.
int get hashCode => hash2(name, options);
^^^^^
P.s 当我只在这样的任何文件中导入它时会发生错误
import 'package:firebase_storage/firebase_storage.dart';
【问题讨论】:
hash2()
来自与firebase
包无关的quiver
包。你把import 'package:quiver/core.dart';
放在你的文件里了吗?顺便说一句,您需要运行 flutter pub get
然后在添加新包后重建您的应用程序。热重载不会让你立即使用新包
我试过了,没用。我什至创建了另一个应用程序并向我显示了相同的错误消息,所以我重新安装了 Flutter,它现在可以工作了。
解决了升级flutter版本清缓存的问题。
【参考方案1】:
我也遇到了这个问题,并且遇到了几种可能导致它的情况。
第一个:这可能是您的环境变量中的损坏路径。您可以通过在终端中执行简单的“echo %PATH%”并删除那些不指向有效位置的路径来检查所有路径。
第二个:确保您的项目路径不包含“&”,如此处所述:https://github.com/flutter/flutter/issues/41547
第三个:我发现的另一个问题是,在卸载 Anaconda 后,它在命令处理器注册表中遗漏了一个 AutoRun 键(在您的情况下,它可能是 Firebase)。
在 regedit 中检查这些地方是否有损坏的链接: 计算机\HKEY_CURRENT_USER\软件\微软\命令处理器 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\命令处理器
【讨论】:
谢谢。 (第三个)解决了我的问题。以上是关于Flutter:如何解决系统找不到指定的路径的主要内容,如果未能解决你的问题,请参考以下文章
记录:如何解决MultipartFile类的transferTo()上传图片报“系统找不到指定的路径“问题亲测有效