Open In App

Flutter – Circular Icon Button

Last Updated : 21 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will implement how to make a circular icon button in Flutter. A sample image is given below to get an idea about what we are going to do in this article.

 

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Add the material package that gives us the important methods and then call the runApp method in the main function that will call our application.

import 'package:flutter/material.dart';
void main() {
runApp(RunMyApp());
}

Step 3: Now we have to make a stateless widget RunMyApp Because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more.

class RunMyApp extends StatelessWidget {
const RunMyApp({super.key});
@override
Widget build(BuildContext context) {
  return MaterialApp(home:);
}
}

Step 4: Give the home property and there can be a scaffold widget that has the property of AppBar and body. AppBar allows us to give the title of AppBar, color, leading, and trailing icon. Now give Body and contains the centered elevated button. Now we have a button, the task is to make it circular. By giving the style to the button we can make it circular and use the shape parameter. Shape further has CircleBorder that gives a circular shape to the button.

// elevated button
ElevatedButton( 
           onPressed: () {},
           child: Icon(Icons.menu, color: Colors.white), // icon of the button
           style: ElevatedButton.styleFrom( // styling the button
             shape: CircleBorder(),
             padding: EdgeInsets.all(20),
             backgroundColor: Colors.green, // Button color
             foregroundColor: Colors.cyan, // Splash color
           ),
         ),

Final Code

Dart




import 'package:flutter/material.dart';
  
void main() {
  runApp(RunMyApp());
}
  
class RunMyApp extends StatelessWidget {
  const RunMyApp({super.key});
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.green),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Circular Icon Button'),
        ),
        body: Center(
          // elevated button
          child: ElevatedButton( 
            onPressed: () {},
            // icon of the button
            child: Icon(Icons.menu, color: Colors.white), 
            // styling the button
            style: ElevatedButton.styleFrom( 
              shape: CircleBorder(),
              padding: EdgeInsets.all(20),
              // Button color
              backgroundColor: Colors.green, 
              // Splash color
              foregroundColor: Colors.cyan, 
            ),
          ),
        ),
      ),
    );
  }
}


Output

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads