VOOZH about

URL: https://www.geeksforgeeks.org/flutter/textbutton-class-in-flutter-material-library-with-examples/

⇱ TextButton Class in Flutter Material Library with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TextButton Class in Flutter Material Library with Examples

Last Updated : 23 Jul, 2025

Text Button Class in Flutter is a material component button widgets with no border by default. It is just a regular button with some text written as the label. TextButton class is a replacement for the deprecated FlatButton class. It is undeprecated and performs all the functions of a FlatButton.  To use a TextButton, you need to import the material package library i.e."package:flutter/material.dart". It can be used for navigation, in toolbars, dialog boxes, etc. 

Constructor of TextButton

TextButton({
Key? key,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
ValueChanged<bool>? onHover,
ValueChanged<bool>? onFocusChange,
ButtonStyle? style,
FocusNode? focusNode,
bool autofocus = false,
Clip clipBehavior = Clip.none,
required Widget child
})

Parameters of TextButton

A TextButton in Flutter comes with two major parameters:

1. child: This is the button's label

 TextButton(

child: const Text('Text Button'),

),

2. onPressed: This shows the action to be performed on pressing the button

 TextButton(
onPressed: () => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const NewScreen())),
child: const Text('Flat Button'),
),

Properties of TextButton

Property

Description

autofocus

Gives a boolean value corresponding to the initial focus of the button

clipBehaviour

Decides whether the content is clipped or not

focusNode

Represents the focus node of the widget

ButtonStyle

Decides the styling of the button

onLongPress

The action to be executed when the button is long-pressed by the user

enabled

Gives a boolean value for the activity of the button

hashcode

Decides the hashcode of the button

Key

Controls how one widget replaces another widget in the tree

onFocusChanged

A method to be executed on changing the focus of the button

onHover

Acting to be executed when the user hovers over the button

runType

Represents the runtime of an object

enabled

Tells whether the button is active or inactive

Adding Colors to the Button

1. : It is the color of all items that are in TextButton.


Output:

👁 foreground


2. : It is the background color of TextButton.


Output:

👁 background

Add ing icon to the Button 


Output:

👁 icon_text_button


Changing the Shape of the Button


Output:

👁 shape_text_button


Changing Elevation 


Output:

👁 elevation_text_button


Adding Padding 


Output:

👁 Padding


Adding ShadowColor


Output:

👁 shadow_color


Let's understand the above properties with an example

Example

main.dart:


Output:

Comment
Article Tags:

Explore