When I launch the app, the background color works, but the image doesn't show. I have my assets folder in my root directory, and the directory address is matched correctly, but the error persists.
I followed these steps and have this as my pubspec.yaml:
flutter_native_splash:
color: "#000000"
image: assets/icon_500.png
My image size is 500x500 and is a png. (I've tried other sizes as well but ex. 120x120, 200x200 to no avail)
here is my code that runs
void main() {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
WidgetsFlutterBinding.ensureInitialized();
runApp(const Main());
FlutterNativeSplash.remove();
}
I ran these terminal commands:
flutter clean
flutter pub get
flutter pub run flutter_native_splash:remove
flutter clean
flutter pub get
flutter pub run flutter_native_splash:create
Here is my pubspec.yaml file
name: todo_time_app
description: A new Flutter project.
publish_to: "none"
version: 1.0.0+1
environment:
sdk: ">=2.18.6 <3.0.0"
dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_local_notifications: ^13.0.0
flutter_native_timezone: ^2.0.0
localstorage: ^4.0.0+1
rxdart: ^0.27.7
dev_dependencies:
flutter_lints: ^2.0.0
flutter_test:
sdk: flutter
flutter_native_splash: ^2.2.17
flutter_native_splash:
color: "#000000"
image: assets/icon.png
android: true
ios: true
web: false
android_gravity: fill
ios_content_mode: scaleAspectFill
fullscreen: true
flutter:
uses-material-design: true
assets:
- assets/
*Edit: I moved the flutter native splash as a dev dependency to see if anything would change. It was initially a regular dependency.
*Edit 2: I've checked my drawables located at "android\app\src\main\res", and the images are generated properly but they are not showing up when I run the app.
*Solution: I added "android_12:" under "flutter_native_splash:" with seperate image and color and it worked.
picture of my issue
Use this Version:
flutter_native_splash: ^2.2.16
it will work
Description of problem: I am trying to add the launcher icon in the pubspec.yaml file but it is showing me this error.
I have tried to even add assets too in the flutter but still not working. When I run flutter pub get no error is shown.
Then I run the command as mentioned in the flutter pub run flutter_launcher_icons:main getting above error.
dependencies:
flutter:
sdk: flutter
retrofit: any
json_annotation: ^3.1.1
provider: ^4.3.1
shared_preferences: ^0.5.8
http: ^0.12.1
flushbar: ^1.10.4
dio: ^3.0.10
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
retrofit_generator : any
json_serializable: ^3.5.1
build_runner: any
flutter_launcher_icons: any
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
# optionally, as transparency is not allowed on app store
# remove_alpha_ios: true
flutter_icons:
android: true
ios: true
image_path: "assets/icons/ic_launcher_square.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
It is because of the wrong indentation as I was facing the same problem but now it worked for me
dev_dependencies:
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
flutter_launcher_icons: "^0.10.0"
flutter_icons:
android: true
ios: true
image_path: "assets/images/cloudy.png"
take care of the spacing behind the lines you are writing
or take a look here
I'm trying to use the error with flutter flutter_launcher_icons plugin to change the launcher icons.
Before I replaced the icons in the folder but this time I want to use this plugin made for that, but I get an error when I run:
flutter pub run flutter_launcher_icons:main
Here is the error:
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
shared_preferences: ^2.0.12
google_fonts: ^2.2.0
flutter_screenutil: ^5.0.3
animated_text_kit: ^4.2.1
shake: ^2.0.0
shake_event: ^0.0.9
flutter_launcher_icons: ^0.9.2
flutter_icons:
image_path_android: "assets/icone-appi.png"
image_path_ios: "assets/icone-appi.png"
android: true
ios: true
I tried to modify the spaces in the writing, but nothing changes.
I thought it would be easier to set up, but I can't find the error.
Thank you for your help
1. Set up the config FIle
add your logo file (ex: logo.png) into assets folder, you have to create the folder first
add flutter_launcher_icons packages in your pubspec.yaml
add a line like this to your package's pubspec.yaml
dev_dependencies:
flutter_launcher_icons: ^0.9.2
flutter_icons:
android: true
ios: true
iamge_path: "assets/logo.png"
2. Run the package
After setting up the configuration, all that is left to do is run the package in the terminal.
flutter pub get
flutter pub run flutter_launcher_icons:main
so this the widget_test.dart
and these are the problems
check pubspec.yaml file whether you have included flutter and flutter_test appropriately
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
and make sure indentation in yaml file is correct.
if problem does not solved. run flutter clean and flutter pub get
I keep getting
Running "flutter packages get" in flutter_sportters...
Error on line 6, column 5 of pubspec.yaml: A dependency may only have one source.
sdk: flutter
^^^^^^^^^^^^^
When I run my app or Packages Get.
It worked perfectly fine before. Have no idea how to fix this.
Consider you are going to use this package "shared_preferences".
You will get this error in pubspec.yaml. If you did like below.
dependencies:
flutter:
sdk: flutter
shared_preferences: v0.4.2
Indention is important you are accidentally adding shared_preference package below flutter dependency. So the error "A dependency may only have one source"
Correct format below:
dependencies:
flutter:
sdk: flutter
shared_preferences: v0.4.2 #no indention
It throws an error because of Indention. It is important to maintain Indention while adding a dependency in flutter.
Before :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
After :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
Hope this will solve your error.
Happy coding!!!
Indentation !!!
Being newbees making silly mistakes. I have written the new dependency inside the flutter root as :
dependencies:
flutter:
sdk: flutter
sqflite:
Instead of
dependencies:
flutter:
sdk: flutter
sqflite:
Comment when you see the difference!!
I was trying to add assets folder to my project. I added it under dependencies which caused the error:
dependencies:
flutter:
sdk: flutter
assets:
- images/
It's not to be added under dependencies. Instead, add it under flutter:
flutter:
uses-material-design: true
assets:
- images/
You can define just like that in pubspec.yaml file
dependencies:
flutter:
sdk: flutter
image_picker: 0.4.1
and flutter packages get you can call via terminal or if you are using Android Studio than options availbale above when you edit pubspec.yaml file.
In terminal go to your project directory and then enter flutter packages get
I solve My problem:
Here my first Code
dependencies
flutter:
sdk: flutter
webfeed: ^0.4.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
after I change it
dependencies:
flutter:
sdk: flutter
webfeed: ^0.4.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
I thing you must to put your package name in the same number colunm of flutter: and cupertino_icons:
Check indentations as flutter package in pubspec.yaml takes single dependency source.
make sure, the name of your project is not same as any package ,
this too cause for this error
open your pubspec.yaml file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
country_code_picker: ^1.0.4
Other answers are correct. I would also like to add that I was trying to add shared_preferences and even though my indentation was correct, I was still getting the error mentioned in the question. To resolve it I changed the name of my project as it was also shared preferences
I kept getting this error no matter what I did, including commenting out the new lines. Finally, I put them back in with the correct indentation and ran the program. The problem magically resolved itself. However, the indentation is critical.
I am getting this error due to duplication of a package in dependencies
i.e:
dependencies:
flutter:
sdk: flutter
**cupertino_icons: ^0.1.2**
english_words: ^3.1.5
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
I solved this error by removing duplication then Flutter clean and then Flutter Packages Get.
Its due to indentation: check out correct way
name: flutter_app
description: A new Flutter application.
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
http: "0.11.3+17"
autocomplete_textfield: ^1.6.4
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
I ran into the same problem turns out the name of my app and the package name were same which resulted into this error.
name of the app scrapy and the dependency was also scrapy...
Changed the name and it worked.
After checking all other solutions if the problem still persists
make sure whether the specified library is installed correctly or not. This error also encounter when the library is not installed correctly.