Flutter, the go-to framework for developers building scalable and interactive cross-platform applications, offers unparalleled flexibility and performance. To create captivating and user-centric app experiences, incorporating Flutter icons is paramount.

Guide: Adding Flutter Icon Widgets

Sparkleo Technologies
4 min readJan 3, 2024

Flutter, the go-to framework for developers building scalable and interactive cross-platform applications, offers unparalleled flexibility and performance. To create captivating and user-centric app experiences, incorporating Flutter icons is paramount.

For crafting a successful app, the fusion of innovative ideas, strategic thinking, and best practices is essential. By seamlessly integrating these elements, you can create a compelling end-product. And when it comes to user interface design, flawless execution and the strategic use of design elements, including icons, can greatly enhance user retention and engagement.

This blog post aims to provide a comprehensive understanding of the Flutter icon library and how to effectively customize icons to suit your app’s needs.

Introduction to Flutter Icons

As we design the user interface of our apps, we encounter an array of elements like sliders, text fields, buttons, dropdown lists, checkboxes, tags, search fields, toggles, and more. Among these, Flutter icons hold a prominent position, deserving their rightful place in our apps.

The Flutter framework equips developers with an icon widget that boasts an extensive collection of icons. Leveraging the pre-existing icons available within the icon class eliminates the need to design icons from scratch. This sets Flutter icons apart from other notable Flutter widgets like Flutter Conditional Show Widget, Flutter InkWell Widget, Flutter FocusNode Widget, or Flutter Inherited Widget.

Now, let’s dive into the process of adding icons to your Flutter app using the icon widget.

Types of Icons in Flutter

Flutter Material Design Icons

Material Design Icons are a rich set of beautiful and pixel-perfect icons for use in your Flutter applications. They are included in the Flutter framework and can be used directly without any additional setup.

Flutter Cupertino Icons

Cupertino Icons are a set of iOS-style icons that can be used to give your Flutter app an iOS look and feel. They are also included in the Flutter framework and can be used without any additional setup.

Flutter Custom Icons

Besides the pre-designed Material and Cupertino icons, Flutter also empowers you to incorporate your own custom icons. This feature proves handy when you desire to utilize a distinctive icon that isn’t readily available in the standard sets or when you aim to uphold a consistent visual style throughout your app.

Adding an Icon in Flutter

To incorporate an icon into your Flutter app, leverage the Icon widget and specify the desired icon by its name. Let’s take a look at an example of adding a simple home icon:

Adding Material Icons

To use a Material Design icon, you simply need to create an Icon widget and pass in the icon you want to display. The Icons class provides a list of all available Material Design icons.

1     // Example of using a Material Design icon in Flutter
2 Icon(Icons.home, color: Colors.black[450])

Adding Cupertino Icons

To use a Cupertino icon, you need to create an Icon widget and pass in the icon you want to display. The CupertinoIcons class provides a list of all available Cupertino icons.

1     // Example of using a Cupertino icon in Flutter
2 Icon(CupertinoIcons.star_fill, color: Colors.yellow[500])

Using Custom Icons

Using Custom Icons

To utilize custom icons, you’ll first need to add the icon images to your project. These images should be placed in the assets folder located in your project’s root directory. Next, you’ll need to declare these assets in the pubspec.yaml file. This ensures that Flutter knows where to locate them.

Here’s an example of how to declare assets in the pubspec.yaml file:

1     // Example of declaring assets in pubspec.yaml
2 flutter:
3 assets:
4 - assets/my_icon.png

Once the assets are declared, you can use the Image.asset function to display your custom icon.

1     // Example of using a custom icon in Flutter
2 Image.asset('assets/my_icon.png')

Changing Icon Size

In addition to altering the color, you can adjust the size of icons in Flutter. This can be accomplished by setting the size property within the Icon widget. The default size is 24.0, but you have the flexibility to increase or decrease it based on your requirements.

// Here's an example of changing the size of an icon
Icon(Icons.home, color: Colors.black[450], size: 32.0)
// Here's an example of changing the size of a Cupertino icon
Icon(CupertinoIcons.star_fill, color: Colors.yellow[500], size: 36.0)
// Here's an example of changing the size of a custom icon
Image.asset('assets/my_icon.png', width: 48.0, height: 48.0)

Customizing Icons in Flutter

In addition to size modification, icons can also be customized by adjusting their opacity and rotation. This can be achieved by utilizing the opacity and angle properties within the Icon widget.

// Here's an example of customizing an icon by adjusting its opacity
Icon(Icons.home, color: Colors.black[450], opacity: 0.8)
// Here's an example of customizing an icon by rotating it
Icon(Icons.home, color: Colors.black[450], angle: 45.0)

Using Icons in Different Widgets

Icons can be seamlessly integrated into various widgets to create a cohesive and visually appealing user interface. Some commonly used widgets where icons can be added include FloatingActionButton, ElevatedButton, IconButton, BottomNavigationBarItem, and more.

// Here's an example of using an icon in a FloatingActionButton
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => print('Add new item'),
// Here's an example of using an icon in an ElevatedButton
ElevatedButton.icon(
icon: Icon(Icons.save),
label: Text('Save Changes'),
onPressed: () => print('Save button pressed'),

Conclusion

This blog post has served as a comprehensive walkthrough on how to integrate icons in your Flutter app. Additionally, we’ve shared insights on adapting Flutter font size based on screen size. We hope that this information has been both insightful and valuable to you.

Stay tuned for more updates and guides related to Flutter app development. Our upcoming blog post will delve into how to add custom icons in Flutter or harness the power of images as icons.

If you have any questions or suggestions, please feel free to leave a comment. For top-notch Flutter app development services, consider hiring Flutter developers from Sparkleo Technologies.

--

--

Sparkleo Technologies

We provide the bridge between the real and digital world by building IoT based solutions. - https://www.sparkleo.io/