FlatButton Widget in Flutter
Last Updated :
25 Apr, 2023
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. The later class will eventually be removed from flutter SDK, so it is suggested to move to the newer class.
List of replaced classes:
- FlatButton → TextButton
- RaisedButton → ElevatedButton
- OutlineButton → OutlinedButton
- ButtonTheme → TextButtonTheme, ElevatedButtonTheme, OutlineButtonTheme
Constructor of FlatButton class:
Syntax:
FlatButton({Key key, @
required VoidCallback onPressed,
VoidCallback onLongPress,
ValueChanged<bool> onHighlightChanged,
MouseCursor mouseCursor,
ButtonTextTheme textTheme,
Color textColor,
Color disabledTextColor,
Color color,
Color disabledColor,
Color focusColor,
Color hoverColor,
Color highlightColor,
Color splashColor,
Brightness colorBrightness,
EdgeInsetsGeometry padding,
VisualDensity visualDensity,
ShapeBorder shape,
Clip clipBehavior: Clip.none,
FocusNode focusNode,
bool autofocus: false,
MaterialTapTargetSize materialTapTargetSize,
@required Widget child})
Properties:
- child: the button's label.
- textColor: the color of the text.
- color: the color of the button.
- splashColor: the splash color of the button.
- shape: the shape of the flat button.
- onPressed: the required callback function.
- onLongPress: the callback function when the button is long pressed.
Example:
The main.dart file
Dart
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FlatButton',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String txt='';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks'),
backgroundColor: Colors.green,
),
backgroundColor: Colors.lightBlue[50],
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
// splashColor: Colors.red,
color: Colors.green,
// textColor: Colors.white,
child: Text('Flat Button',),
onPressed: () {
setState(() {
txt='FlatButton tapped';
});
},
),
Text(txt,textScaleFactor: 2),
],
),
),
);
}
}
Output:
If the properties are defined as below:
FlatButton(
color: Colors.green,
child: Text('Flat Button',),
onPressed: () {
setState(() {
txt='FlatButton tapped';
});
},
),
The following design changes can be observed:

If the properties are defined as below:
FlatButton(
color: Colors.green,
textColor: Colors.white,
child: Text('Flat Button',),
onPressed: () {
setState(() {
txt='FlatButton tapped';
});
},
),
The following design changes can be observed:

If the properties are defined as below:
FlatButton(
splashColor: Colors.red,
color: Colors.green,
textColor: Colors.white,
child: Text('Flat Button',),
onPressed: () {
setState(() {
txt='FlatButton tapped';
});
},
),
The following design changes can be observed:

Explanation:
- Create FlatButton with the child as a Text widget.
- When the button is tapped, onPressed function will be called and set the txt to "FlatButton tapped".
- Give the button color as green.
Similar Reads
Flutter Tutorial This Flutter Tutorial is specifically designed for beginners and experienced professionals. It covers both the basics and advanced concepts of the Flutter framework.Flutter is Googleâs mobile SDK that builds native Android and iOS apps from a single codebase. It was developed in December 2017. When
7 min read
Top 50 Flutter Interview Questions and Answers for 2025 Flutter is an open-source, cross-platform application development framework. It was developed by Google in 2017. It is used to build applications for Android, iOS, Linux, Mac, Windows, and the web. Flutter uses the Dart programming language. It provides a simple, powerful, efficient, and easy-to-und
15+ min read
What is Widgets in Flutter? Flutter is Google's UI toolkit for crafting beautiful, natively compiled iOS and Android apps from a single code base. To build any application we start with widgets - The building block of Flutter applications. Widgets describe what their view should look like given their current configuration and
5 min read
Flutter | An introduction to the open source SDK by Google Flutter is Googleâs Mobile SDK to build native iOS and Android, Desktop (Windows, Linux, macOS), and Web apps from a single codebase. When building applications with Flutter, everything is Widgets â the blocks with which the flutter apps are built. They are structural elements that ship with a bunch
5 min read
Android Studio Setup for Flutter Development This article will show how to set up Android Studio to run Flutter Applications. Android Studio is one of the popular IDE( integrated development environment  ) developed by Google itself to create cross-platform Android applications. First, you have to install Android Studio version 3.0 or later, a
3 min read
10 Best Flutter Projects with Source Code in 2025 Are you eager to begin your journey into Flutter app development but find yourself unsure of where to start? Look no further! This article serves as a comprehensive guide for aspiring developers, offering a wide range of innovative Flutter project ideas. Whether you're looking to refine your skills
7 min read
Flutter - Architecture Application Flutter architecture application mainly consists of: WidgetsGesturesConcept of StateLayersWidgetsWidgets are the primary component of any flutter application. It acts as a UI for the user to interact with the application. Any flutter application is itself a widget that is made up of a combination of
3 min read
Flutter - Changing App Icon Flutter SDK is an open-source software development kit for building beautiful UI which is natively compiled. When we create a Flutter Project, it comes with the default Flutter icon. In order to get the app published in stores like Google Play Store, Apple App Store, etc the default icon can be chan
3 min read
Flutter - AppBar Widget AppBar is usually the topmost component of the app (or sometimes the bottom-most), it contains the toolbar and some other common action buttons. As all the components in a Flutter application are a widget or a combination of widgets. So AppBar is also a built-in class or widget in Flutter which give
7 min read
Scaffold class in Flutter with Examples The Scaffold is a class in flutter that provides many widgets or we can say APIs. The Scaffold will expand or occupy the whole available space in device screen .The class Hierarchy is as follows:Object â³ Diagnosticable â³ Diagnosticable Tree â³ Widget â³ StateFul Widget â³ ScaffoldThe constructor of the
8 min read