Display Icon Button in Flutter

Display Icon Button in Flutter

An icon button is a button that contains only an icon without a text label.

A IconButton class is used to create an icon button. We can change a color of the icon using color property. But there is no option to specify a background color.

import 'package:flutter/material.dart';

void main() => runApp(const MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('Icon button')),
        body: Center(
            child: IconButton(
          icon: const Icon(Icons.volume_up),
          color: Colors.indigo,
          onPressed: () {
            print('Pressed');
          },
        )));
  }
}

Leave a Comment

Cancel reply

Your email address will not be published.