flutter
  1. flutter-buttons

Flutter Buttons

Flutter provides several types of buttons for different use cases. In this tutorial, we will learn about the various types of buttons in Flutter and their usage.

Syntax

The syntax for creating buttons in Flutter is as follows:

ButtonType(
  onPressed: (){}, // Callback Function
  child: Text("Button Text"), // Widget
  textColor: Colors.white, // Text Color
  color: Colors.blue, // Background Color
)

Example

Let's create a simple raised button example:

RaisedButton(
  onPressed: (){},
  child: Text("Click Me"),
)

Output

Flutter Raised Button

Explanation

We have created a simple raised button widget with a text "Click Me" displayed on it. We have provided an empty callback function in the onPressed property which is executed when the button is pressed.

Use

Buttons can be used for several purposes in an app, such as triggering an action when clicked, navigating to another screen or page, or submitting a form.

Important Points

  1. The onPressed property takes a callback function as a parameter.
  2. Button widgets can be decorated with text, icons, and images.
  3. Flutter provides different types of buttons such as RaisedButton, FlatButton, and OutlineButton for different use cases.

Summary

In this tutorial, we discussed the syntax and usage of buttons in Flutter. We also learned about the different types of buttons that can be used for different purposes. Buttons are an essential element in building interactive interfaces in Flutter apps.

Published on: