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:
Flutter - Custom Tab Bar
Next article icon

Flutter - Custom Gradient CheckBox

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Flutter is famous for its UI components and its development. There are many widgets available with multiple properties to customise. Let's create a custom gradient checkbox. A sample video is given below to get an idea about what we are going to do in this article.


Checkbox in Flutter is a material design widget. It is always used in the Stateful Widget as it does not maintain a state of its own. We can use its onChanged property to interact with or modify other widgets in the Flutter app. Like most of the other flutter widgets, it also comes with many properties like activeColor, checkColor, mouseCursor, etc, to let developers have full control over the widget’s look and feel.

Step By Step Implementation

Let's learn from step-by-step implementation

Step 1: Let's create a basic flutter app or use existing code

We can create an app by the command in the terminal

Dart
flutter create . 

or create it from Android Studio.

Step 2: Let's add 1 bool variable in our stateful widget

Dart
  bool isChecked = false; 

This variable we will use for checking the state of custom gradient checkbox

Step 3: Now we will create 1 Container for creating checkbox with below properties

In this container we have few properties which you can change as per your requirement

Properties:

  • height, width: We have added fixed height width so that it remains same in responsiveness also
  • alignment: We haved Alignment.center as all the child will be requiring incenter only
  • decoration: In Box Decoration there multiple properties you can use and modify this checkbox but I have used only 2 properties. 1 most important gradient in this we will be passing the linear gradient with 2 different colors and borderradius for making checkbox beautiful.
Dart
 Container(            // Fixed height and width is given so that               // it won't get change in responsiveness            width: 40,            height: 40,            alignment: Alignment.center, // Alignment as center            decoration: const BoxDecoration(                   // TODO: you can change here gradient color                   gradient: LinearGradient(                     colors: [                       Color(0xFFF09869),                       Color(0xFFC729B2),                     ],                   ),       borderRadius: BorderRadius.all(Radius.circular(6)), ), 

Step 4: Add following child in this container

Add Inkwell as its child as we will requiring it in next step to change the state of checkbox

Dart
Container(                 // Fixed height and width is given so                  // that it won't get change in responsiveness                 width: 40,                 height: 40,                 alignment: Alignment.center, // Alignment as center                 decoration: const BoxDecoration(                   // TODO: you can change here gradient color                   gradient: LinearGradient(                     colors: [                       Color(0xFFF09869),                       Color(0xFFC729B2),                     ],                   ),                   borderRadius: BorderRadius.all(Radius.circular(6)),                 ),                 child: InkWell(                                ),               ), 

Step 5: Change the state of bool variable

In Inkwell we have added onTap where I willbe changing the state of isChecked variable

Dart
onTap: () {             // To change the state of isChecked variable             setState(() {                       isChecked = !isChecked;                     });            }, 

Step 6: With the help of Ternary operator we will add two different widgets inside button

As we are making custom gradient checkbox we need to handle how it will looks when check box is not selected or when it is selected. So we haved handled this from ternary operator by using 2 simple widgets 1st is Icon and 2nd is container with white color or background color. When isChecked is true we have give icon of check as it shows that checkbox is slected and if value is false we have pass plain container.

Dart
 InkWell(           onTap: () {                     // To change the state of isChecked variable                     setState(() {                       isChecked = !isChecked;                     });                   },                   // TODO: Here you can see border of checkbox if                       // ischecked is true , else gradient color of checkbox                   child: isChecked                       ? const Icon(Icons.check_rounded, color: Colors.white)                       : Padding(                           padding: const EdgeInsets.all(2.5),                           child: Container(                             decoration: BoxDecoration(                                 color: Colors.white,                                 borderRadius: BorderRadius.circular(5)),                           ),                      ),                 ) 

Here's go You have successfully created the custom gradient checkbox. You can use the below source code in your app.

Source Code of Checkbox

Dart
Container(                 // Fixed height and width is given so that                   // it won't get change in responsiveness                 width: 40,                 height: 40,                 alignment: Alignment.center, // Alignment as center                 decoration: const BoxDecoration(                   // TODO: you can change here gradient color                   gradient: LinearGradient(                     colors: [                       Color(0xFFF09869),                       Color(0xFFC729B2),                     ],                   ),                   borderRadius: BorderRadius.all(Radius.circular(6)),                 ),                 child: InkWell(                   onTap: () {                     // To change the state of isChecked variable                     setState(() {                       isChecked = !isChecked;                     });                   },                   // TODO: Here you can see border of checkbox if                    // ischecked is true , else gradient color of checkbox                   child: isChecked                       ? const Icon(Icons.check_rounded, color: Colors.white)                       : Padding(                           padding: const EdgeInsets.all(2.5),                           child: Container(                             decoration: BoxDecoration(                                 color: Colors.white,                                 borderRadius: BorderRadius.circular(5)),                           ),                     ),                 ),               ), 

Complete Source Code

Dart
import 'package:flutter/material.dart';  // You can also use stateful builder // instead of stateful widget class GradientCheckBox extends StatefulWidget {   const GradientCheckBox({Key? key}) : super(key: key);    @override   State<GradientCheckBox> createState() => _GradientCheckBoxState(); }  class _GradientCheckBoxState extends State<GradientCheckBox> {   bool isChecked = false;   @override   Widget build(BuildContext context) {     return Scaffold(         appBar: AppBar(           leading: IconButton(             icon: const Icon(Icons.arrow_back_ios),             onPressed: () {               Navigator.pop(context);             },           ),           title: const Text('Gradient CheckBox'),           backgroundColor: Colors.green,         ),         body: Center(           child: Column(             mainAxisAlignment: MainAxisAlignment.center,             children: [               Container(                 // Fixed height and width is given so                 // that it won't get change in responsiveness                 width: 40,                 height: 40,                 alignment: Alignment.center, // Alignment as center                 decoration: const BoxDecoration(                   // TODO: you can change here gradient color                   gradient: LinearGradient(                     colors: [                       Color(0xFFF09869),                       Color(0xFFC729B2),                     ],                   ),                   borderRadius: BorderRadius.all(Radius.circular(6)),                 ),                 child: InkWell(                   onTap: () {                     // To change the state of isChecked variable                     setState(() {                       isChecked = !isChecked;                     });                   },                   // TODO: Here you can see border of checkbox if                    // ischecked is true , else gradient color of checkbox                   child: isChecked                       ? const Icon(Icons.check_rounded, color: Colors.white)                       : Padding(                           padding: const EdgeInsets.all(2.5),                           child: Container(                             decoration: BoxDecoration(                                 color: Colors.white,                                 borderRadius: BorderRadius.circular(5)),                           ),                         ),                 ),               ),               const SizedBox(                 height: 20,               ),               Text(                 'Custom Gradient CheckBox',                 style: Theme.of(context).textTheme.displaySmall,               ),             ],           ),         ));   } } 

Output:


Next Article
Flutter - Custom Tab Bar
author
flutterwings
Improve
Article Tags :
  • Dart
  • Flutter
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

  • Flutter - Gradient Button
    Buttons are the building block of any Android Application, Buttons are helping in to perform specific tasks like Navigating from one screen to another screen, Showing the Toast, Sign-in, Sign-up buttons, and many more. But giving the effects of the colors to the Button makes the Button more pretty.
    3 min read
  • Flutter - Custom Gradient Switch
    If you are using Flutter you must hear that it is very easy to make UI in this. All widgets are easy to use. So now let's make one common widget that you must have seen in almost every app i.e. Switch. Now you will say it is very easy to make from the switch widget. But we will make it a Gradient Sw
    5 min read
  • Flutter - Checkbox Widget
    Checkbox in Flutter is a material design widget. It is always used in the Stateful Widget as it does not maintain its own state. We can use its onChanged property to interact with or modify other widgets in the Flutter app. Like most of the other flutter widgets, it also comes with many properties l
    4 min read
  • Flutter - Custom Widgets
    We create Custom Widgets when we want a custom look and feel to our app, and we know that there will be a repetition of a particular widget. We can create the custom widget in a new dart file with all the codes and defining the parameters that we need in the constructor. For more on how to split wid
    8 min read
  • Flutter - Custom Tab Bar
    In this article, we will see about the Custom Tab Ba, and also how you can create the tab bar inside the tab bar. Making the tab bar is very easy you just go and return the default controller and give the length and Make the tab bar, But In this article, we will see how you can create the tab bar an
    5 min read
  • Flutter - Customizable Ratings bar
    Rating Bar as the name suggests is used to rate content inside the application. More or less all applications use them either to gate user feedback on their application or to get a rating for content hosted by the application. Applications like IMDB use them to rate movies and Television series wher
    7 min read
  • Flutter - Gradient AppBar
    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
    5 min read
  • Flutter - Custom Bottom Navigation Bar
    A bottom navigation bar is a material widget that is present at the bottom of an app for selecting or navigating to different pages of the app. It is usually used in conjunction with a Scaffold, where it is provided as the Scaffold.bottomNavigationBar argument. Though Flutter provides you with the B
    9 min read
  • Flutter - CheckboxListTile
    CheckboxListTile is a built-in widget in flutter. We can say it a combination of CheckBox with a ListTile. Its properties such as value, activeColor, and checkColor are similar to the CheckBox widget, and title, subtitle, contentPadding, etc are similar to the ListTile widget. We can tap anywhere on
    6 min read
  • Flutter - Custom Clipper
    In flutter, we have widgets and properties that help to create custom shapes. In this article, we will learn about a property called Custom Clipper and we will also implement it to create a curve shape in our UI design. What is a Custom Clipper? Custom Clipper is a property that helps to clip the wi
    3 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