How to use Custom Icons in Flutter(Using SVG or Icon Font)?
Many icons are predefined in the flutter and are very easy to use. Many times though, just these icons are not enough. For example, if you want to show an icon of a particular company or logo etc, you'll have to reach for other than the official icons.
So, Let's see how you can add custom icons to your flutter project
Social Media Icon |
Let's say you want to use the above social media icon. As of now, there is no pre-made package on pub.dev, so you'll have to add them yourself. This method will only work for any icon pack which has SVG icon font.
Converting for the use in Flutter
The first step is obviously you need to download the icon pack(SVG). If you are following along with the above icon, get it from this download page.
Once you have downloaded the SVG icon, you need to somehow convert these into icons to be able to use them in your flutter project.
Thankfully, There's one open-source tool fluttericon.com which can do the conversion for you.
Steps to proceed with fluttericon.com
- Drag the SVG font file or icons to the webpage
- Select the icons you want.
- Give your Custom Flutter icon pack a name( this will also be used as the class name)
- Download the zip file.
Using it in Flutter
After extracting the zip file you want to get the ttf file located under the fonts folder of extracted zip into your flutter project.
I created an icons folder so that regular fonts won't get mixed up with icon fonts.
This is a regular font file so you need to add it as a font asset in pubspec.yaml
pubspec.yaml
…
flutter:
…
fonts:
- family: AssetIcons
fonts:
- asset: assets/icons/AssetIcons.ttf
…
assets_icons.dart
class AssetIcons {
AssetIcons._();
static const _kFontFam = 'AssetIcons';
static const String? _kFontPkg = null;
static const IconData socialMedia = IconData(0xe800, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
USAGE:
import
'assets_icons.dart';
...
Icon(AssetsIcons.socialMedia,
size: 25),
...
#Flutter
Nice Write up. Although, We analyze the major market participants – Flutter vs. React Native. Read to know more details : Flutter Vs React Native
ReplyDeleteDart has many great benefits for developers, as seen in this post. Developers can use it as a compiler or executor to develop robust, fast, and superior apps. Both Google’s products make Flutter and Dart the most dangerous duo. They also support other Google products. Companies and entrepreneurs should hire Flutter developers who are experienced before anyone else. Contact Insync for the premium quality service by the industry expert Flutter Developers in the market.
ReplyDelete