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
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
TextSpan Widget in Flutter
Next article icon

Flutter - Gradient TextFields

Last Updated : 08 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Decorating text fields can be a big task if you have a large application. There is a package gradient_textfield that could make this time-consuming task pretty simple and fast. Although in Flutter we can create text fields using TextField, for beginners especially, it takes time to understand decoration concept, gradient_textfield can do this easily. We will see how simple it is through examples in this article.

Add the dependency:

Dart
 dependencies:   gradient_textfield: ^0.0.1 

Or run the following command in the terminal of IDE:

flutter pub add gradient_textfield

Import in main.dart:

Dart
import 'package:gradient_textfield/gradient_textfield.dart'; 

Implementation:

Initialize TextEditingController. 

Dart
TextEditingController name = TextEditingController(); 

To create gradient text fields use Gradienttextfield() widget. We can modify its properties like radius, height, width, etc. In the future, there will be more properties added to Gradienttextfield by the package author.

Example 1:

Dart
Gradienttextfield(                 controller: name,                 radius: 40,                 height: 60,                 width: 400,                 colors: const [Colors.pink, Colors.red, Colors.orange],                 text: "Enter Name",                 fontColor: Colors.black,                 fontSize: 15,                 fontWeight: FontWeight.normal,               ), 

Output:

Example 2:

Dart
  Gradienttextfield(                 controller: name,                 radius: 2,                 height: 60,                 width: 400,                 colors: const [Colors.yellow, Colors.green],                 text: "Enter Email",                 fontColor: Colors.black,                 fontSize: 15,                 fontWeight: FontWeight.normal,               ), 

Output:

Example 3:

We can create small text fields for taking OTP as input also using this package. The below example shows the way we can create such small text fields with different colors and styles.

Dart
  Row(                 children: [                   Gradienttextfield(                     controller: name,                     radius: 40,                     height: 60,                     width: 60,                     colors: const [Colors.grey, Colors.black],                     text: "ABC",                     fontColor: Colors.white,                     fontSize: 15,                     fontWeight: FontWeight.normal,                   ),                   Gradienttextfield(                     controller: name,                     radius: 40,                     height: 60,                     width: 60,                     colors: const [Colors.green, Colors.yellow],                     text: "DEF",                     fontColor: Colors.white,                     fontSize: 15,                     fontWeight: FontWeight.normal,                   ),                   Gradienttextfield(                     controller: name,                     radius: 0,                     height: 60,                     width: 60,                     colors: const [Colors.grey, Colors.black],                     text: "GHI",                     fontColor: Colors.white,                     fontSize: 15,                     fontWeight: FontWeight.normal,                   ),                   Gradienttextfield(                     controller: name,                     radius: 20,                     height: 60,                     width: 60,                     colors: const [Colors.deepPurple, Colors.blue],                     text: "JKL",                     fontColor: Colors.white,                     fontSize: 15,                     fontWeight: FontWeight.normal,                   ),                 ],               ) 

Output:

Full Example:

Dart
import 'package:flutter/material.dart'; import 'package:gradient_textfield/gradient_textfield.dart';  void main() {   runApp(MyApp()); }  class MyApp extends StatelessWidget {   TextEditingController name = TextEditingController();   @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Create Gradient TextFields',       theme: ThemeData(         primarySwatch: Colors.green,       ),       home: Scaffold(         appBar: AppBar(           title: Text("GeeksForGeeks"),           centerTitle: true,         ),         body: Container(           child: Column(             mainAxisAlignment: MainAxisAlignment.center,             children: [               Gradienttextfield(                 controller: name,                 radius: 40,                 height: 60,                 width: 400,                 colors: const [Colors.pink, Colors.red],                 text: "Enter Name",                 fontColor: Colors.black,                 fontSize: 15,                 fontWeight: FontWeight.normal,               ),               SizedBox(height: 20),               Gradienttextfield(                 controller: name,                 radius: 2,                 height: 60,                 width: 400,                 colors: const [Colors.green, Colors.yellow],                 text: "Enter Email",                 fontColor: Colors.black,                 fontSize: 15,                 fontWeight: FontWeight.normal,               ),             ],           ),         ),       ),     );   } } 

Output:


Next Article
TextSpan Widget in Flutter

R

rn540
Improve
Article Tags :
  • Flutter
  • Android
  • Flutter UI-components

Similar Reads

  • Multiline TextField in Flutter
    Multiline TextField is the input TextField which takes the input in more than one line, This type of TextField is used in the scenario like taking Feedback from the user, User Comments, and Description, etc., We can achieve multiline TextField by setting the property keyBoardType and maxLines of the
    2 min read
  • Retrieve Data From TextFields in Flutter
    In this article, we'll learn how to retrieve data from TextFields. TextField() widget is the most common widget used in flutter apps to take user input. We'll talk about two major methods used to extract text from TextField. Using VariablesThe TextField widget has various callback properties through
    4 min read
  • Flutter - Slider with Gradient
    In this article, we will create a slide to confirm the button using the widget in Flutter. A sample video is given below to get an idea about what we are going to do in this article. Step By Step Implementation Step 1: Create a New Project in Android Studio To set up Flutter Development on Android S
    3 min read
  • TextSpan Widget in Flutter
    TextSpan is an immutable span of text. It has style property to give style to the text. It is also having children property to add more text to this widget and give style to the children. Let's understand this with the help of an example. Constructors:Syntax: TextSpan({String text, List<InlineSpa
    3 min read
  • Flutter - RichText Widget
    The RichText widget is used to display text that uses various different styles. The displayed text is described using a tree of TextSpan objects, each of which has its own associated style that is used for that subtree. Depending on the layout constraints the text might break across multiple lines o
    3 min read
  • Flutter - Add Gradient Effect to ListTile
    In Flutter, a gradient effect is a visual effect that smoothly transitions between two or more colours, creating a gradual blend or progression of colours. To add a gradient background to a ListTile in Flutter, you can wrap the ListTile with a Container or another widget that supports gradients, suc
    3 min read
  • Flutter - Scrollable Text
    In this article, we are going to make a Flutter application in which we will add a Text Widget that can be scrolled horizontally or vertically. These can have a wide range of applications depending upon the needs of the users. Here we will be implementing the simplest form of scrollable text. We can
    3 min read
  • 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 - Show/Hide Password in TextField
    In this article, we will Implement how to show/hide the password in the Textfield. A sample video is given below to get an idea about what we are going to do in this article. Step by Step Implementation Step 1: Create a New Project in Android Studio To set up Flutter Development on Android Studio pl
    3 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
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