Flutter : "Could not resolved the package" every install new packages

Zef*_*ndo 8 dart flutter

I have some problem about installing new package from pub.dev. I create my own package inside my root project with this command :

flutter create --template=package main_template

structure folder

结构文件夹

I installing new package inside main_template not lib. every install new package in main_template i received this error :


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)

Run Code Online (Sandbox Code Playgroud)

Until now i trying install 3 package [Cache Network Image,Device Info , SplashScreen]. And all packages give me that error.

How can i fixed it ?

Pra*_*han 12

你用的是vs代码吗?

只需重新启动或关闭 vs 代码应用程序(所有窗口),然后再次打开它运行

扑扑酒吧得到


小智 7

此命令解决了我的问题:

扑扑酒吧得到


R R*_*ara 0

我和你有同样的问题。就我而言,我有 2 个模块(包即coreshared)。在shared模块中,我添加了一个新包,例如shimmercached_network_image用于创建自定义小部件。另外,我可以import使用我已经在模块中添加的包shared。但是在运行该项目后,我收到了类似Could not resolved the package .... 因此,要修复它,我只需添加shimmercached_network_image打包到我的根项目中。为此,我已经添加了2x包。在shared模块和根项目中。所以我认为如果出现该错误,您也应该这样做。

就我而言,这需要 2x 将新包添加到 pubspec.yml 中,分别是json_serializable,,shimmercached_network_image

并不是所有的都必须添加两次,只有那些导致错误的才添加。