The file "assets/background.png" set as the parameter "image" was not found. pub finished with exit code 1 - flutter

I am trying to create a splash screen using flutter_native_splash 1.3.1 package. I created a folder called 'assets' in the lib folder and added that image to that folder. But I am getting the error mentioned in the question when I ran 'flutter pub run flutter_native_splash:create' in the command line.
I added the following lines in pubspec.yaml as suggested by the package documentation.
flutter_native_splash:
color: "#000000"
image: assets/background.png
Can someone please explain what I might be missing?

Do the following steps
Add flutter_native_splash: ^1.3.1 in pubspec.yaml
Create flutter_native_splash.yaml in root of project at same level as pubspec.yaml
Add below content in the above file
flutter_native_splash:
color: "#000000"
image: assets/background.png
Run this command in terminal
flutter pub run flutter_native_splash:create
With above steps, splash screen will load properly but the error you mentioned might come. To remove that error enable below section in pubspec.yaml
assets:
- assets/background.png
6.Make sure you have assets directory in the root of project and background.png is present inside it.
7.Clean and build. it should work without any issues

Continuing the Ehtesham Siddiquie answer.
I think the assets folder should be at the root of the project (at the same level of pubspec.yaml and flutter_native_splash.yaml). but u created it in the lib folder.

Related

flutter pubspec.yaml deleted after updating

Hello experts I am facing very big issue I am made application in 2021 on flutter my application is still live on play store now I need update it, problem is that I updated my android studio flutter version 3.0. Now opening my old project which was made in 2021 after opening it my pubspec.yaml file is missing in the project, I don't no how to recover that file or repair it. They have a lot of dependencies included there is pubspec.lock file available but not pubspec.yaml please please help me i am in big check screen shot below
if i use flutter create command i am getting this errors
You can create a pubspec.yaml file on root directory or open the bottom terminal and try flutter create . it will provide default structure. Now to get pub package, check the import section and add on pubspec.yaml
If you have a backup then paste the pubspec.yaml file from it. Else take a backup of the project. Run flutter create . in the root directory. It will create the pubspec file in the project. Click on configure dart and add the flutter path then run the project. It will throw errors for the packages used manually enter packages in pubspec or you can try flutter pub add <packagename>

FileNotFoundError with flutter_dotenv

I installed flutter_dotenv with this command:
flutter pub add flutter_dotenv
My is pubspec.yaml is like:
dependencies:
flutter:
flutter_dotenv: ^5.0.0
flutter:
assets:
- .env
Then I put .env file in the project root (I will use .env.dev. .env.prd later so you see them in the screen shot):
I run project from VSCode then get FileNotFoundError:
I checked the .env file location hundred of times, tried to change the file name, change the location to /lib etc - still no luck. Any idea?
I found what was wrong. "assets:" must be under "flutter:", so tab is necessary before "assets:". That's it!
flutter:
assets:
- .env

Could not find a file named "pubspec.yaml" when auto generating code with build_runner

After I have updated Flutter to v1.22 using code generation with build_runner was not working. I was told that the proper command to use in this version was:
dart pub run build_runner watch --delete-conflicting outputs
However, I receive the following error:
Could not find a file named "pubspec.yaml" in "C:\Users\jpiab\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\_fe_analyzer_shared-2.2.0".
I have no idea why it is looking for pubspec.yaml in that folder, since that folder is not the current working directory.
--- EDIT ---
The file exists in path:
C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-2.2.0
dart is just looking for it in the wrong place. Any ideas on how to fix it?
I solved for me. I use Android Studio in Ubuntu 20.04.01 LTS.
Firstly run this command:
flutter pub get
After run this command:
flutter packages pub run build_runner build
Or:
flutter packages pub run build_runner watch
Source: https://github.com/flutter/flutter/issues/50092
Deleting the .pub-cache folder.
and then run pub get
Edit:
If above method won't work then delete the folder
C:\Users\jpiab\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org_fe_analyzer_shared-2.2.0
and then run pub get from within your project directory.
That same error I had and I resolved it by aligning my dependencies. Check if your build_runner is in the same line as flutter_test if you added it to dev_dependencies.
Error Corrected
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: [latest]
My Error
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: [latest]
I fixed it by changing the environment variable PUB_CACHE to the right folder.
TL;DR
Make sure you run the flutter command from the project's root directory.
As you can see, Running the command from a specific folder reproduces this error while everything works as expected from the project's root directory.

Error in terminal while running flutter pub get: Response:

I am new to flutter and SO, I tried this Flutter force higher package dependency version,
My code was
dependencies:
intl: ^0.15.0
I replaced it with
dependency_overrides:
intl: ^0.16.0
But I still get this error
$ flutter pub get
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.
This isn't a pubspec issue. You're simply executing the command from the wrong directory.
cd into the directory where your flutter project files are. That will be the folder that contains other folders like, build, android, ios, lib along with the pubspec.yaml file. Run flutter pub get from there.
Go to the root of your project, where the lib and other directories exist. Then run the command. The best is to use the terminal of your code editor as the path would be same as root of your project in there.

How can I run an example from a Flutter package/library?

I have the following simple directory structure:
flutter_published
.idea
android
build
ios
lib
main.dart
flutter_published.iml
pubspec.lock
pubspec.yaml
network_to_file_image
.idea
example
main.dart
lib
network_to_file_image.dart
test
network_to_file_image.iml
pubspec.lock
pubspec.yaml
network_to_file_image is a package.
There are two main.dart files, one at flutter_published/lib/main.dart and
another at flutter_published/network_to_file_image/example/main.dart
I am able to run the first one, but not the one inside of the example directory under network_to_file_image. The second one gives me this error:
Launching example\lib\main.dart on Android SDK built for x86 in debug mode...
No application found for TargetPlatform.android_x86.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
Also, when the app is generated, what happens to the example and test directories of the packages I use? Are they included or removed from the final app that is deployed?
To solve this, instead of the main.dart file inside of the example directory, you need to create a complete Flutter application-type project inside of the example directory. Then, the example tab will point to the README.md file inside of that directory.
That example directory will have its own lib directory, containing a main.dart file. Since that file is now inside of an application-type directory it can be run.
Visit this repo to see how it works:
https://github.com/marcglasberg/async_redux/tree/master/example
Update:
To be clear, the example's pubspec.yaml file can reference its package by using a relative reference. For example, here is the dependencies section of the example dir of the async_redux package I mentioned:
dependencies:
http: ^0.13.1
async_redux:
path: ../
flutter:
sdk: flutter
Since the example dir is at the same level as the package's pubspec.yaml file, then the example's own pubspec.yaml is one level below it. Thus, it may reference the package itself by using a ../ path:
async_redux:
path: ../
example/main.dart only exists to be shown in https://pub.dartlang.org/packages/network_to_file_image#-example-tab-
The pub site is limited in how it finds content in the example directory to display in the Example tab.
cd to the directory and execute flutter create .. You should be able to run it afterwards
Go to the example folder of the repository of the package.
Open the lib folder and go to the main.dart file.
Above the void main() function, you can see the Run|Debug|Profile (pic below), click on the one you want to run the project as.
The example app will now run in your emulator.
The screenshot below is of the chewie package available on pub.dev