How to use custom icon in flutter, using android studio! I need to know what we want to do in pubspec.yaml. Because I got an error in pubspec.yaml, cant view a icon in our program.
It can help if you specify what sort of icon you are trying to add, and if you share some of your pubspec file. Are we talking about an app icon (using a package like flutter_launcher_icons) or icons to use within the app (like the ones created via fluttericon.com).
I'll assume you're talking about launcher icons.
First make sure you have the package:
https://pub.dev/packages/flutter_launcher_icons
In the root of your pubspec.yaml file, you can add lines like:
flutter_icons:
android: true
ios: true
image_path: "assets/myIcon.png"
adaptive_icon_background: "#ffffff"
adaptive_icon_foreground: "assets/myIconForeground.png"
This will use myIcon.png for the iOS app, and apply the foreground image on a white background for Android (where depending on your phone, a circular or square icon can be used).
Now you may notice the asset paths, you can also add the icons as assets to your app such that you can use them elsewhere.
flutter:
...
assets:
- assets/myIcon.png
- assets/myIconForeground.png
After which you should be able to run the plugin and generate your native icons:
flutter pub run flutter_launcher_icons:main
Related
I have tried to remove these codes.
flutter_icons:
android: true
ios: true
image_path: "1024.png"
adaptive_icon_foreground: "512.png"
flutter_native_splash:
android: true
ios: true
image: "A.png"
The app still works successfully.
So, is it safe to remove these?
These are tools to generate app icon and splash screen, so yes it is safe after generate those to remove them, but when yo decide to change app icon or splash screen you need to add them again.
It is working properly in all devices including web except android 12 devices. I tried too many ways to figure it out, but am not able to find solution. If anyone knows solution please reply as soon as possible.
The problem is in android 12 devices, logo which I have used isn't showing.In other devices it working perfectly.
Here I am attaching my pubspec.yaml dev_dependencies info:-
dev_dependencies:
flutter_test:
sdk: flutter
flutter_native_splash: ^2.2.3+1
flutter_lints: ^2.0.0
flutter_native_splash:
image: assets/images/splash.png
color: "#23AA49"
android: true
android12: true
ios: true
android_12:
image: assets/images/splash.png
color: "#23AA49"
Apps targeting Android 12 and higher are required to specify an explicit value for android:exported
Make these changes
android:exported="true"
Update targetSdkVersion and compileSdkVersion
you can refer to this
https://developer.android.com/about/versions/12/migration
Hope this helps you
enter image description hereFollow this picture you can see build.gradle file go there and then follow second picture
search this potion of file and modified it as per my screenshot
then in same file modified this line also
Go to Your android->app when you noticed that build.gradle file just open it and. modify it it contains targetsdkversion and compilesdkversion aslo
click on this link you will show one image then modify your puspec.yamel file i have no such reputation so i can not embeded image in post right now after 10 i get that right so you have to click on this link
I am facing trouble using the flutter native splash screen.A blank screen appears when i tried to use the flutter_native_splash package https://pub.dev/packages/flutter_native_splash
You can create native splash screen for both (android, iOS) platform manually to follow the doc (https://docs.flutter.dev/development/ui/advanced/splash-screen) but I will recommend you to use flutter_native_splash plugin cause it will save your time and create less opportunity of mistakes.
Create a new assets and logos folder in your root project path and place your splash_screen_logo.png like this [project_name]/assets/logos/splash_screen_logo.png
Add flutter_native_splash: ^2.2.16 at dev_dependencies in pubspec.yaml (please replace ^2.2.16 version with the latest version number. Check it)
dev_dependencies:
flutter_test:
sdk: flutter
flutter_native_splash: ^2.2.16
Paste this below code in your pubspec.yaml and change the color and image asset path
flutter_native_splash:
color: "#071b5d"
image: assets/logos/splash_screen_logo.png
android: true
ios: true
Finally in your project path terminal, run this command: flutter pub run flutter_native_splash:create and it will generate native splash screen for both android and iOS.
The actual and perfect way is not to add a page or use a plugin, you can even do it natively by this method:
Go to => andoid > app > main > res > drawable > in this folder you can see a file called lauch_background open it,
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/white" />
<!-- You can insert your own image assets here -->
<item>
<bitmap
android:gravity="fill"
android:src="#mipmap/ic_launcher" />
</item>
</layer-list>
add your image in the folder and rename the image file name to ic_launcher. Also uncomment the commented code in the file.
refer this example for you native splash screen
https://www.codegrepper.com/code-examples/whatever/flutter+native+splash+screen
Two Packages are Needed If you want to Add a Native Flutter Splash screen and Change App Icon using Easy Method
flutter_native_splash 2.2.16
flutter_launcher_icons
Flutter native splash screen and App icon change - Easy Method
this is the right code, the right indentation matters
flutter_native_splash: ^2.2.16
flutter_native_splash:
color: "#004ab9"
images: assets/finviobackground.png
android: true
ios: true
I am new to flutter and recently tried to develop a test app for learning sake with latest version Flutter 2.5. By looking at some tutorial online, I have added flutter_native_splash: ^1.2.3 package for splash screen. And works fine.
However, when I launch app for the first time, it shows following debug message
W/FlutterActivityAndFragmentDelegate(18569): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
After visiting the above link, I am not able to understand much what is supposed to be done.
Code in pubspec.yaml
flutter_native_splash:
color: "#FFFFFF"
color_dark: "#000000"
image: assets/images/splash_720.png
android: true
ios: true
android12: true
Also, compileSdkVersion and targetSdkVersion is set to 31 in build.gradle
Please help. Thanks in advance.
To avoid that warning you just need to remove that API usage from your project.
Remove these lines of code from the AndroidManifest.xml file.
Previously, Android Flutter apps would either set io.flutter.embedding.android.SplashScreenDrawable in their application manifest, or implement provideSplashScreen within their Flutter Activity. This would be shown momentarily in between the time after the Android launch screen is shown and when Flutter has drawn the first frame. This is no longer needed and is deprecated – Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn the first frame. Developers should instead remove the usage of these APIs. - source
UPDATE (FLUTTER 2.8.0)
As per the flutter 2.8.0 update, The newly created project doesn't have this warning.
They removed unused API from Androidmanifest.yml but still have belove mentioned code.
Remove the below lines from the android manifest file. It's no longer used
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"/>
I have an application composed of a number of different Dart and Flutter packages.
This has proven useful in that I've been able to move things like fonts, colours and Widgets into an independent style guide package which we can then use across all of our other applications.
Using custom fonts in a package works slightly differently in Flutter as we need to add the assets directory as a child of lib rather than a sibling:
…and then register these assets in pubspec.yaml like so:
assets:
- packages/receipt_widget/assets/fonts/my_font.ttf
// other asset declarations
This, for custom fonts and icons (png, jpg etc) works completely fine. My issue is that the same approach does not work for custom icon fonts.
Steps:
Generate custom icon font using IcoMoon or Flutter Icon
Place the generated font into the assets/fonts directory as demonstrated above
Place the generated dart file into the lib folder
Reference the custom icon in code and place into an Icon widget like so:
Icon(MyFontIcon.ic_heart);
For safety I then run flutter clean and uninstall the app from the device/ emulator before deploying a clean build.
I'm then left with a question mark rather than the referenced icon.
NB. the very same icons work correctly when used in a Flutter application directly rather than in a package.
To use your Flutter Icon font from a custom package, you can follow these steps:
(I repeated some of your steps already, for others who will find this issue)
create a flutter icon font
You can use flutter icon for that https://www.fluttericon.com
Put the file into your package
Make sure to copy the .ttf file into of the /lib folder.
NOT just assets, as you would do in your root project.
Example path:
/packages/my_awesome_fontpackage/lib/assets/MyIconFont.ttf
(see https://zubairehman.medium.com/how-to-use-custom-fonts-images-in-flutter-package-c2d9d4bfd47a )
Add the font to your project
Now open your package's pubspec.yaml file and add the font as an asset with package path:
flutter:
fonts:
- family: MyIconFont
fonts:
- asset: packages/my_awesome_fontpackage/assets/MyIconFont.ttf
(you might have to restart your app and bundling completely for the font to be loaded correctly and maybe run flutter clean just to be sure)
Now add package declaration to font dart file
Go into the my_icon_font.dart file and change the constant _kFontPkg there to your package name.
class MyIconFont {
MyIconFont._();
static const _kFontFam = 'MyIconFont';
static const String? _kFontPkg = 'my_awesome_fontpackage';
static const IconData bell = ...
....
}