我在从pub.dev安装新包时遇到了一些问题。我使用以下命令在根项目中创建了自己的包:flutter create --template=package main_template
结构文件夹
我在main_template而不是lib中安装新软件包。每次在main_template中安装新软件包时,我都收到此错误:
Compiler message:
Error: Could not resolve the package 'device_info' in 'package:device_info/device_info.dart'.
sinergi_flutter_template/main_template/lib/variable/get_device_id.dart:3:8: Error: Not found: 'package:device_info/device_info.dart'
import 'package:device_info/device_info.dart';
^
sinergi_flutter_template/main_template/lib/variable/get_device_id.dart:9:11: Error: 'DeviceInfoPlugin' isn't a type.
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
^^^^^^^^^^^^^^^^
sinergi_flutter_template/main_template/lib/variable/get_device_id.dart:9:47: Error: The method 'DeviceInfoPlugin' isn't defined for the class 'GetDeviceId'.
- 'GetDeviceId' is from 'package:main_template/variable/get_device_id.dart' ('sinergi_flutter_template/main_template/lib/variable/get_device_id.dart').
Try correcting the name to the name of an existing method, or defining a method named 'DeviceInfoPlugin'.
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
^^^^^^^^^^^^^^^^
U
nhandled exception:
FileSystemException(uri=org-dartlang-u
ntranslatable-uri:package%3Adevice_info%2Fdevice_info.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:3)
7)
#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:flut
ter_frontend_server/server.dart:38:22)
#5 starter (package:flutter_frontend_server/server.dart:149:27)
#6 main (file:///C:/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
build failed.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\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.
* Get more help at https://help.gradle.org
BUILD FAILED in 20s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
直到现在我尝试安装3包[缓存网络图像,设备信息,闪屏]。和所有的包给予我这个错误。
我该怎么修呢?
9条答案
按热度按时间brccelvz1#
您是否使用了vs代码?
只需重新启动或关闭vs代码应用程序(所有窗口),然后再次打开它运行
一种扑击棒
wpcxdonn2#
此命令修复了我的问题:
一种扑击棒
ymdaylpp3#
您是否正在使用Android Studio?
那就重新开始吧,我很满意.
确保已运行:
一种扑击棒
r1zhe5dt4#
try this command
flutter clean
and then pub get
try this command incase if u face any cache related issue
flutter pub cache repair
n3ipq98p5#
删除所有模块中的.dart_tool文件夹(如果您有多个模块)帮助我
ghhaqwfi6#
我和你有同样的问题。在我的情况下,我有2个模块(包即
core
和shared
)。在shared
模块中,我添加了一个新的包,如shimmer
和cached_network_image
,用于创建自定义小部件。同样,我可以import
并使用我已经在shared
模块中添加的包。但在我运行项目后,我得到了Could not resolved the package ...
这样的错误信息。所以为了修复它,我只是添加了shimmer
和cached_network_image
包到我的根项目。所以,我已经添加了2x
包。在shared
模块和根项目中。所以我认为你也应该这样做,如果得到这个错误。在我的例子中,这需要向pubspec中添加两个新包。yml是
json_serializable
,shimmer
,cached_network_image
并不是所有的内容都必须添加两次,只添加那些导致错误的内容。
eqqqjvef7#
清除该高速缓存
flutter pub cache clean
对所有软件包
flutter update-packages
运行pub getx6yk4ghg8#
从您的项目中删除.idea文件夹并重新启动android工作室对我来说很好
7rtdyuoh9#
安装
characters
package解决了我的问题。