Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Types
  • Functions
  • Oops
  • Collections
  • Sets
  • Dart Interview Questions
  • Fluter
  • Android
  • Kotlin
  • Kotlin Android
  • Android with Java
  • Android Studio
Open In App
Next Article:
Raised Button widget in Flutter
Next article icon

FlatButton Widget in Flutter

Last Updated : 25 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

simple flatbutton widget

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:

empty flatbutton widget

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:

coloured flatbutton widget

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.


Next Article
Raised Button widget in Flutter
author
singh_teekam
Improve
Article Tags :
  • Dart
  • Flutter
  • Flutter
  • Flutter-Widgets

Similar Reads

  • Flutter - ElevatedButton Widget
    Elevated Button is a Flutter component included inside the material package, i.e., "package:flutter/material.dart". The main characteristic of these buttons is the slight elevation in their surface towards the screen when tapped by the user. In simple language, elevated buttons are un-deprecated rai
    5 min read
  • Flow Widget in Flutter
    The Flow widget in Flutter is a layout widget that positions children's elements in a flow along with sizing and positions its children proficiently using FlowDelegate. It allows you to create a grid-like layout where the children are positioned according to a given alignment, and they flow from one
    4 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
  • Align Widget in Flutter
    Align Widget is the widget that is used to align its child within itself and optionally sizes itself based on the child's size. Align Widget is quite flexible and can change its size according to the size of its child. Constructor of Align class: Syntax: Align({Key key, AlignmentGeometry alignment:
    2 min read
  • Flutter - FlutterLogo Widget
    FlutterLogo widget is as simple as it sounds, it is just the flutter logo in the form of an icon. This widget also comes built-in with Flutter SDK. This widget can found its use as a placeholder for an image or icon. Below we will see its implementation with all its properties and constructor. Const
    3 min read
  • Flutter - DropDownButton Widget
    In this article, we will learn how to use a DropDownButton and learn various properties of it in flutter. We will use the Flutter DropDownButton widget to display a dropdown list in our application. So first let’s see what is DropDownButton. DropDownButton Widget FlutterIn Flutter, A DropDownButton
    4 min read
  • ClipRect Widget in Flutter
    The ClipRect widget is used to clips its child using a rectangle. It associates with the Clippers family. The main use of clippers is to clip out any portion of the widget as required. It behaves similar to that of ClipRRect and is used to Clip a Rectangle portion of the child widget but without the
    2 min read
  • ClipOval widget in Flutter
    ClipOval widget clips the child widget in oval or circle shape. We can reshape the child widget by changing width and height. If width and height are equal the shape will be circular. If the width and height are given differently then the shape will be oval. Let's understand this with the help of an
    2 min read
  • Drawer Widget in Flutter
    Drawer widget is used to provide access to different destinations and functionalities provided in your application. It is represented by three horizontal parallel lines on the upper end of the scaffold. It has a horizontal movement from the edge of the Scaffold that navigates the link to different r
    5 min read
  • ClipRRect Widget in Flutter
    The ClipRRect widget in flutter is used to clips its child using a rounded rectangle. It associates with the Clippers family. The main use of clippers is to clip out any portion of the widget as required. It behaves similar to that of ClipRect and is used to Clip a Rectangle portion of the child wid
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences