我在从pub.dev安装新软件包时遇到了一些问题。我使用package为实现的modularization拆分我的体系结构。这是我项目中的packages (核心和共享)。

我使用这个命令创建core和shared模块flutter create --template=package name_of_modules。
然后在core或shared模块中安装新的软件包。每当我在模块中安装新的软件包时,我都会收到这样的错误:
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Invalid depfile: /Users/rrifafauzikomara/Downloads/MovieCatalogue/.dart_tool/flutter_build/009f5ba5376d66cb437ddc8aa8ed1cad/kernel_snapshot.d
Invalid depfile: /Users/rrifafauzikomara/Downloads/MovieCatalogue/.dart_tool/flutter_build/009f5ba5376d66cb437ddc8aa8ed1cad/kernel_snapshot.d
Compiler message:
Error: Could not resolve the package 'json_annotation' in 'package:json_annotation/json_annotation.dart'.
core/lib/src/network/api/rest_client.dart:2:8: Error: Not found: 'package:json_annotation/json_annotation.dart'
import 'package:json_annotation/json_annotation.dart';
^
core/lib/src/network/api/rest_client.dart:39:2: Error: Method not found: 'JsonSerializable'.
@JsonSerializable()
^^^^^^^^^^^^^^^^
core/lib/src/network/api/rest_client.dart:51:2: Error: Method not found: 'JsonSerializable'.
@JsonSerializable()
^^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Ajson_annotation%2Fjson_annotation.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1 asFileUri (package:vm/kernel_front_end.dart:604:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:472:15)
<asynchronous suspension>
#4 _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:38:22)
#5 starter (package:flutter_frontend_server/server.dart:149:27)
#6 main (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
Failed to build bundle.
Error launching application on iPhone 11 Pro Max.错误的结果总是关于Could not resolved the package的,但是我可以import这个包,也可以使用这个包。但是在我运行这个项目之后,它所显示的错误。这是飞碟上的虫子?以及如何修复它?因为我需要这种方法来使我的项目具有可伸缩性,还需要像在Android本机中那样实现模块化。
这是我flutter doctor -v的结果
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.2 19C57,
locale en-US)
• Flutter version 1.12.13+hotfix.8 at
/Users/rrifafauzikomara/Documents/flutter
• Framework revision 0b8abb4724 (3 months ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/rrifafauzikomara/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build
1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.39.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.5.1
[✓] Connected device (1 available)
• iPhone 11 Pro Max • 641006EC-FDB0-4918-B547-593818B98B05 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
• No issues found!发布于 2020-05-01 07:35:25
我已经通过将它添加到根项目来修复我的issue。因此,我添加了像shimmer 2x这样的新包,一个在shared模块中,一个在根项目中。
并不是所有的都必须添加两次,只添加那些导致错误的内容。
发布于 2020-08-10 20:17:08
我通过“失效缓存/重新启动.”在这里输入图像描述修复了我的
https://stackoverflow.com/questions/61532934
复制相似问题