Title: Flutter : "Could not resolved the package" every install new packages
Tags: flutter;dart
Question: 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();
^^^^^^^^^^^^^^^^
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)
#2      writeDepfile  (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension&gt;
#3      FrontendCompiler.compile  (package:frontend_server/frontend_server.dart:472:15)
<asynchronous suspension&gt;
#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&gt;  (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'.
&gt; 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)
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 ?
Comment: @Abion47 after run `flutter pub get` everything is works!. I think with `flutter packages get` it's enough, but after follow your comment is works.

Comment: @Richard Heap so my `main_template` should be outside of my root project?

Comment: Don't put flutter projects inside other flutter projects. They should be siblings; you'll have your app and package at the same level under, say, `projects`. In the pubspec of one, refer to the other with `path: ../other`.

Comment: yes, because then you can reuse it in a future project.

Comment: Have you added the packages to your pubspec file and run `flutter pub get`?


Here is another answer: Installing the characters package solved my problem.

Here is another answer: remove .idea folder from your project and restart android studio works fine for me

Here is another answer: try this command
flutter clean
and then pub get
try this command incase if u face any cache related issue
flutter pub cache repair

Here is another answer: removing .dart_tool folder in all modules (if you have more than one) helped me
Comment for this answer: and dont forget to flutter clean / flutter pub get, could help too

Here is another answer: I have the same issue as you. In my case, I have 2 modules (package namely core and shared). In shared modules I add a new package like shimmer and cached_network_image for creating a custom widget. Also, I can import and use that package that I already added in shared modules. But after I running the project, I get the error with information like Could not resolved the package .... So to fix it, I just add shimmer and cached_network_image package into my root project. So for this, I already add 2x package. In shared modules and in the root project. So I think you should do it too if getting that error.
In my case, that requires 2x add new package into pubspec.yml are json_serializable, shimmer, cached_network_image
Not all of it has to be added twice, only those that cause errors are added.

Here is another answer: This command fixed my issue:
flutter pub get

Here is another answer: Are you using Android Studio?
Then just restart it. Worked for me.
Make sure you already have run:
flutter pub get

Here is another answer: Are you using vs code?
just restart or close the vs code app (all window), then open it again an run
flutter pub get

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 8, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:02/05/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<flutter><dart>', 'Title': 'Flutter : "Could not resolved the package" every install new packages', 'ViewCount': 16528, 'id': 60071600, 'user_AboutMe': '<p>Learning PHP , SQL , Dart</p>\n', 'user_AccountId': 9945451.0, 'user_DisplayName': 'Zeffry Reynando', 'user_Reputation': 2853.0, 'user_Views': 389.0, 'user_id': 7360353.0}}