Skip to main content

Types of Buttons In Flutter

Flutter Buttons

Flutter has various types of buttons. Buttons are the Flutter widgets, which are a part of the material design library.So, here We are going to discuss different types of buttons and they can be placed anywhere in our UI as dialogs, forms, cards, and toolbars, AppBar and in many more places.

Types of Flutter Buttons 

1. TextButton

Text Button is a Material Design button that comes without border or elevation change by default.TextButton is the replacement for FlatButton. We are clicking on TextButton then it is the same as Text and click effect if we want the Shadow, ButtonStyle, alignment, padding, and many more properties we can use as per our requirements. There are two required parameters. Of course, you have to pass a Widget as a child and onPressed.

Taking an example that has text, style, and onPressed properties in style there are many properties we can customize like primary color, background color, surface, shape, and many more. 

For defining a style for a specific button, you can pass ButtonStyle as a style parameter in the constructor of TextButton.Values passed as the parameters of TextButton.style from.

We are discussing more properties of TextButton in the upcoming Blog.

2. Elevated Button

Elevated Button is a Material Design's button that comes with the default elevation that will increases when the button is pressed. Elevated Button is the replacement for Raised Button. There are two required parameters. Of course, you have to pass a Widget as a child and onPressed.

The style of the button can be customized by creating a ButtonStyle. The ButtonStyle can be passed as ThemeData's elevatedButtonTheme or ElevatedButton's style. 

Here in the example we are defining a style for a specific button, you can pass ButtonStyle as a style parameter in the constructor of ElevatedButton.in this you can define a TextStyle specific for the button and pass it as textStyle.

We are discussing more properties of ElevatedButton in the upcoming Blog. 

3. Floating Button

I have already used Floating Button in early blogs here we are discussing more properties of Floating Button how we can customize and use it as per our requirements. The floating Button default showing at the bottom but you can change it as per your design.

Here in the example, there are 2 floating buttons. First, with the Text Widget and another is with the Icon and in that, you can customize all the values. 

Example With Text 
Example With Icon


4. Outline Button

Outline Button as per the widget name it's gives a default outline to the button you can change it and also customize it. 

There are two ways to pass the ButtonStyle. First, we can set the styleform of the Outline Buttonin the style property. Second, you can set it as theme data. You need to create an OutlinedButtonThemeData and pass it as outlinedButtonTheme in the constructor of ThemeData. By setting the style as theme data, it affects all OutlinedButton widgets under the tree.

We have seen the first type of styleform in another button example here we can see the second way which is OutlinedButtonThemeData Let' see the example.
OutlinedButtonThemeData

Example of OutlinedButton 

5. Icon Button

In Flutter IconButton is a widget that prints an icon on top of the Material widget. there are two required parameters: icon and onPressed. the icon is the icon to be displayed it is Widget as an Icon. onPressed is a callback function called when the button is pressed.
 
The icon color can be changed using a color parameter. You can also set the colors when the button is pressed, disabled color, hover color, and many more properties for customization. So, let's see the example where we can see all these properties:- 

6. DropDown Button 

If you have an input field and you want the users to select only from certain values at that time you can use the dropdown button.

We use the Dropdown Button to display any Dropdown List item as we can change its style according to it. Which shows the list item we have selected. The Dropdown Button has DropDownMenuItem.
 
Let's take an example in which I have taken the list of language in String data type with the use of items property you can pass your list of items that you want to show in DropDownMenuItem. 


7. PopupMenu Button

PopUpMenu as per the given name popup means how they popup on our screen to show us various options on the click. You can execute a different function on the press of a popup menu as per our need.

In this, we are defining a list of values for that we are using itemBuilder which provides us an index to keep track of our buttons. There are two ways we can use this First, Here is the example we can use basic PopupMenuButton and properties:- 

Second, We can set this in AppBar with the use of action property. So, here we are creating PopUpItem in which we have to declare the index and its values and that we will pass in the popUpMenuButton:- 
PopupItem Class:-
Example of PopMenuButton:-

Comments

Popular posts from this blog

Flutter BottomNavigationBar

BottomNavigationBar A material widget that's displayed at the bottom of an application. Which shows around three to five items and it includes labels and icons. BottomNavigationBar allows you to select one item at a time and quickly navigate to a given page. Properties of the BottomNavigationBar : items: It defines the list of BottomNavigationBar Items to display the bottom navigation bar. currentIndex: It determines the current active bottom navigation bar item on the screen. onTap: It is called when we tapped one of the items on the screen. iconSize: It is used to specify the size of all bottom navigation item icons. fixedColor: It is used to set the color of the selected item. If we have not set a color to the icon or title, it will be shown. type: It determines the layout and behavior of a bottom navigation bar. It behaves in two different ways that are:  1. fixed: Default it is fixed and If it is null, it will use fixed. 2. shifting: It will use shifting where w

MaterialApp and Scaffold in Flutter with Example

What is MaterialApp Material design is for Google Android material design which is used to create UI for Android.MaterialApp is a predefined class in a flutter that extends the Material Design class. It is likely the main or core component of flutter. We can access all the other components and widgets provided by Flutter SDK. It is a class that creates an instance of [WidgetsApp] . Text widget, AppBar widget, Scaffold widget, ListView widget, StatelessWidget, StatefulWidget, IconButton widget, TextField widget, and many more widgets that are accessed using MaterialApp class.  For iOS, there is the Cupertino widgets class which I'll describe or discuss or explain in another article. What is Scaffold In Flutter Scaffold is a very useful and highly flexible class. Scaffold implements the basic material design layout structure. A Scaffold Widget provides a framework that implements the flutter app's basic material design visual layout structure.  The developer can implement a wide

Flutter TextField with Examples

Introduction to TextField TextField in Flutter is the most commonly used text input widget that allows users to collect inputs from the keyboard into an app. We can use the TextField widget in building forms, sending messages, creating search experiences, and many more. By default, Flutter decorated the TextField with an underline. We can also add several attributes with TextField, such as label, icon, inline hint text, and error text using an InputDecoration as the decoration. If we want to remove the decoration properties entirely, it is required to set the decoration to null. 1. decoration It is used to show the decoration around TextField.The most common attributes in decoration are as follows: border : It is used to create a default rounded rectangle border around TextField. labelText : It shows the label text on the selection of TextField. hintText : It shows the hint text inside TextField when there is no text entered.   TextField(               decoration: InputDecoration(