Flutter - Working with Material Button
Last Updated :
04 May, 2025
Buttons are material components that provide the user a single tap facility for taking actions, making choices, submitting forms, saving data, opening a new page, etc. Buttons are triggered when the user taps on them. They are the most commonly used feature provided in almost all Flutter apps. For using buttons, you need to import the Material Components package for Flutter, i.e., "package:flutter/material.dart". Based on their classification, buttons are divided into two categories - deprecated and non-deprecated. The button works on material apps only.
Special features of a Button
- Easy addition of different child widgets for different purposes
- Easy theming of the buttons
- Easy addition of themed text and icons
- Provide action functionalities
Buttons are classified broadly into the following categories:
- Text Button
- Icon Button
- Floating Action Button
- Elevated Button
- Dropdown Button
- PopUp Menu Button
Given below is a brief description of each of the categories:
1. Text Button
The simplest of all the buttons is a text button. They are regular text without any outline or boundary.
Example:
Dart
TextButton(
child: Text(
"Text Button",
style: TextStyle(
color: Colors.green,
),
),
onPressed: () {},
),
Output:
2. Icon Button
These are picturized buttons with colors filled inside them. Icon Buttons represent a cartoonish image of the category defined inside. These are used to create profile screens, option tabs, etc.
Example:
Dart
IconButton(
icon: Icon(Icons.code, size: 50),
color: Colors.green,
onPressed: () {},
),
Output:
3. Floating Action Button
These are small circular buttons that hang on the screen of the application. You can set the position of your action button by using but by default, it is placed at the center of the screen. They create a hovering effect when tapped.
Example:
Dart
FloatingActionButton(
child: Icon(Icons.person),
backgroundColor: Colors.green,
foregroundColor: Colors.white,
onPressed: () {},
),
Output:
4. Elevated Button
This button has a special feature of increased elevation. When an elevated button is pressed, its elevation is increased to a certain value. They do not offer straightforward styling like the rest of the buttons, but you can use a styleFrom method to style an elevated button explicitly.
Example:
Dart
ElevatedButton(
child: Text(
'ElevatedButton',
),
onPressed: () {},
),
Output:
5.Drop Down button
These buttons provide an option to choose from a list of available options. It is a drop-down list.
Example:
Dart
// Current Dropdown value
String dropdownvalue = 'Profile';
// List of Dropdown items
var items = [
'Profile',
'Settings',
'Account',
'Go Premium',
'Logout',
];
// Code for actual DropdownButton
DropdownButton(
focusColor: Colors.green,
value: dropdownvalue,
icon: const Icon(Icons.keyboard_arrow_down),
items: items.map((String items) {
return DropdownMenuItem(
value: items,
child: Text(
items,
style: TextStyle(
color: Colors.green,
),
),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
dropdownvalue = newValue!;
});
},
),
Output:
6. Pop Up Menu Button
It is represented by three vertical dots. It displays a menu bar from which the user selects their chosen option.
Example:
Dart
PopupMenuButton(
itemBuilder:
(context) => [
PopupMenuItem(child: Text("Profile"), value: 1),
PopupMenuItem(child: Text("Account"), value: 2),
PopupMenuItem(child: Text("Settings"), value: 1),
PopupMenuItem(child: Text("About GFG"), value: 1),
PopupMenuItem(child: Text("Go Premium"), value: 1),
PopupMenuItem(child: Text("Logout"), value: 1),
],
),
Output:
Given below are the basic steps you always need to perform while creating a button.
- Create a parent widget for whom you want to set your button as a child
- Add the child property for the respective parent widget
- Explore the requirements of your app and choose which type of button you want to add to it.
- Declare the button and add the styling.
- Modify your button using the in-built theming properties provided by the material package.
Example:
Suppose you want to create a raised button that has an icon of a favorite titled alongside "GeeksforGeeks is" as text.
- Step 1: Since it is an elevated button that will have a text widget and an icon side-by-side, let's enclose it in a Column widget as its parent.
- Step 2: Create a child property to which well will assign our button.
- Step 3: Add the required theming to your button according to your choice.
- Step 4: Add an elevated button and icon to your column
- Step 5: Beautify your button.
Implementation:
Dart
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'GeeskforGeeks';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(
title: const Text(_title),
backgroundColor: Colors.green,
),
body: MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
color: Colors.green,
onPressed: () {},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'GeeksforGeeks is',
style: TextStyle(
color: Colors.white,
),
), // <-- Text
Icon(
// <-- Icon
Icons.favorite,
size: 24.0,
),
],
),
),
);
}
}
Output:
Similar Reads
Flutter Material Widget - Outlined Button Class
Outlined Widgets are material design components that are used to give outlines to buttons. It is in no way different from text buttons except for the special feature of the border this class provides. These contain nonprimary actions for the apps. It is introduced in version 1.22 of flutter. Outline
4 min read
Flutter - Working with Layouts
Before talking about Layout in Flutter, there is just one thing to keep in mind that âEverything in Flutter is Widget". Meaning the core of the layout in any Flutter Application is the widget. Putting it simply, all the images, icons, labels and text, etc are technically widgets of different types a
6 min read
Flutter - Material Banner Widget
In this article, we will learn about a new feature called Material Banner which is a new feature in flutter and got released in flutter version 2.5.0. What is Material Banner? A banner displays an important message and asks the user to perform some action. Banner is displayed at top of the screen be
4 min read
Flutter - Working with Callback Functions
In this article, we will see how we can use callback functions in flutter. We will learn about different methods to implement callback functions in flutter. Callback is basically a function or a method that we pass as an argument into another function or a method to perform an action. In the simples
3 min read
Raised Button widget in Flutter
RaisedButton is the material design button based on a Material widget that elevates when pressed upon in flutter. It is one of the most widely used buttons in the flutter library. Let's understand this button with the help of an example. Disclaimer: As of May 2021 the RaisedButton class in flutter i
5 min read
Flutter - Gradient Button
Buttons are the building block of any Android Application, Buttons are helping in to perform specific tasks like Navigating from one screen to another screen, Showing the Toast, Sign-in, Sign-up buttons, and many more. But giving the effects of the colors to the Button makes the Button more pretty.
3 min read
Flutter - Material Package
Material Package contains the application icon and a lot of designing tool methods. In this package we don't need to write the whole code for the particular function or method, we just import this package and use it single line. How to Install The Material Package For installing the packages we have
2 min read
Flutter - SVG Image as Button
In this article, we will see how to make the SVG image a button in Flutter so that we can perform actions. A sample video is given below to get an idea about what we are going to do in this article. How to Use? You can use the Gesture Detector to add click functionality to any Widget in Flutter. Dar
2 min read
FlatButton Widget in Flutter
FlatButton is the material design widget in a flutter. It is a text label material widget that performs an action when the button is tapped. Let's understand with the help of examples. Disclaimer: As of May 2021 the FlatButton class in flutter is deprecated. TextButton class should be used instead.
3 min read
Flutter - Neumorphic Button
Flutter contains various in-built button types like ElevatedButton, TextButton, etc. But with the help of GestureDetector, we can make any widget perform a set of actions on certain gestures. In this article, we are going to use AnimatedContainer to make a Neumorphic Button in Flutter. The tradition
5 min read