Icon Widget and Attributes
The Icon widget in Flutter is used to display icons in your application. It can represent material icons, custom icons, or even icons from different font packages. Let's explore the key attributes and properties of the Icon widget.
Key Attributes and Properties:
icon:
- The icon attribute is crucial for specifying the icon to be displayed. It takes an IconData object, which can represent a built-in material icon or a custom icon.
Example:
Icon(
Icons.favorite,
color: Colors.red,
size: 30,
)
color:
- The color property sets the color of the icon.
Example:
Icon(
Icons.star,
color: Colors.yellow,
)
size:
- The size property determines the size of the icon.
Example:
Icon(
Icons.mail,
size: 40,
)
Example:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Icon Widget Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Flutter Icon Widget Example',
style: TextStyle(fontSize: 18),
),
SizedBox(height: 20),
Icon(
Icons.favorite,
color: Colors.red,
size: 30,
),
SizedBox(height: 20),
Icon(
Icons.star,
color: Colors.yellow,
size: 40,
),
SizedBox(height: 20),
Icon(
Icons.mail,
size: 50,
),
],
),
),
),
);
}
}
Explanation:
The example demonstrates the usage of the Icon widget with different attributes.
Three instances of the Icon widget are used to display different icons: heart, star, and mail.
The color and size properties are customized to showcase the versatility of the Icon widget.
Subscribe to my newsletter
Read articles from Vinit Mepani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vinit Mepani
Vinit Mepani
"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation. In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology. Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities. In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"