Material Icon example in Flutter

This Article is posted by seven.srikanth at 12/26/2022 1:30:03 AM



In Flutter, you can use the Icons class to display material design icons in your app. Here is an example of how you can use a material icon in a Flutter app:
 

import 'package:flutter/material.dart';
void main() {
  runApp(
    MaterialApp(
      home: MyApp(),
    ),
  );
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: IconButton(
          icon: Icon(Icons.favorite), // Use a material icon
          onPressed: () {
            // Do something when the icon is pressed
          },
        ),
      ),
    );
  }
}
The Icons class includes a number of predefined material icons, such as Icons.favorite, Icons.search, and Icons.add. You can use these icons by passing them as the icon parameter to a widget that displays an icon, such as Icon or IconButton.
You can also customize the appearance of the icon by setting the color and size properties:

IconButton(
  icon: Icon(
    Icons.favorite,
    color: Colors.red,
    size: 32.0,
  ),
  onPressed: () {
    // Do something when the icon is pressed
  },
),
Keep in mind that the material design icon set includes over 1,000 icons, so you can use a variety of icons in your app to communicate different actions and ideas. You can find a full list of the available icons at the Material Design icons website. https://fonts.google.com/icons?selected=Material+Icons 

Tags: Material Icon; Icons;








0 Comments
Login to comment.
Recent Comments













© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com