我对从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个软件包[Cache Network Image,Device Info,SplashScreen]。而且所有软件包都会给我这个错误。
我该如何解决?
答案 0 :(得分:11)
您在使用vs代码吗?
只需重新启动或关闭vs代码应用程序(在所有窗口中),然后再次运行即可将其打开
flutter pub get
答案 1 :(得分:4)
此命令解决了我的问题:
flutter pub get
答案 2 :(得分:0)
我和你有同样的问题。就我而言,我有2个模块(软件包core
和shared
)。在shared
模块中,我添加了一个像shimmer
和cached_network_image
这样的新包,用于创建自定义窗口小部件。另外,我可以import
并使用已经在shared
模块中添加的程序包。但是,在运行项目之后,我得到了诸如Could not resolved the package ...
之类的信息的错误。因此,要解决此问题,只需将shimmer
和cached_network_image
包添加到我的根项目中。因此,为此,我已经添加了2x
包。在shared
模块和根项目中。因此,如果出现该错误,我认为您也应该这样做。
就我而言,这需要2次将新包添加到pubspec.yml中,json_serializable
,shimmer
,cached_network_image
并非所有内容都必须添加两次,而仅添加会导致错误的内容。
答案 3 :(得分:0)
从您的项目中删除.idea文件夹,然后重新启动android studio对我来说效果很好
答案 4 :(得分:-2)
安装characters
package解决了我的问题。