How To Change Flutter Textformfield Cursor Color – Easy Flutter Code Example

flutter textformfield cursor color

In this tutorial, we’ll learn how to easily implement Flutter textformfield cursor color by using a proper practical Flutter example code.

Introduction: Flutter Textformfield Cursor Color

Before implementing Flutter textformfield cursor color, first understand what Flutter textformfield cursor is, Flutter textformfield cursor specifies the current position/location where the input will be inserted in the Flutter textformfield.

Don’t worry, I will now start implementing it using a proper example so you have a better understanding of what that cursor means and how to change Flutter textformfield cursor color.

Default Flutter Textformfield Cursor Color

Let’s see what the default Flutter textformfield cursor color is. For that, you don’t have to specify anything, just implement the Flutter textformfield. See the below code:

TextFormField()
flutter textformfield default cursor color
flutter textformfield widget default cursor color
As you can see, I haven’t specified anything else other than just a Flutter textformfield to see what the default Flutter textformfield cursor color is.
In the above image, you can see that the default Flutter textformfield cursor color is blue and the cursor is shown only when the Flutter textformfield is focused, but we can change its color, let’s now discuss how to change Flutter textformfield cursor color. For that, see the next section.

Change Flutter Textformfield Cursor Color

Let’s see how to change Flutter textformfield cursor color. For that, you have to use the cursor color constructor of the Flutter textformfield. See the below code:

cursorColor: Colors.green
flutter textformfield custom cursor color
We can see that I have passed a red color to the Flutter textformfield cursor color constructor. In the image above, we can see that the cursor color is now red. You can use any other color you want. You can customize the cursor using other constructors as well like cursor height, cursor radius, cursor width.
Congrats, you now have complete understanding of how to change Flutter textformfield cursor color. Now as a treat for making it to the last, I have prepared a beautiful Flutter textformfield for you.
Below section includes the complete source code in which Flutter textformfield cursor color is customized.

Customized Flutter Textformfield Cursor Color Source Code

flutter textformfield cursor color

 

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Homepage(),
    );
  }
}
class Homepage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      body: Center(
          child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 40),
              child: TextFormField(
                style: TextStyle(color: Colors.purple),
                cursorColor: Colors.purple,  // Custom Flutter textformfield cursor color
                decoration: InputDecoration(
                    prefixIcon: Icon(
                      Icons.email,
                      color: Colors.purple,
                    ),
                    suffixIcon: Icon(
                      Icons.visibility,
                      color: Colors.purple,
                    ),
                    labelText: 'Enter your email',
                    labelStyle: TextStyle(color: Colors.purple.withOpacity(.8)),
                    enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.purple),
                        borderRadius: BorderRadius.circular(30).copyWith(
                            bottomRight: Radius.circular(0),
                            topLeft: Radius.circular(0))),
                    focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.purple),
                        borderRadius: BorderRadius.circular(30).copyWith(
                            bottomRight: Radius.circular(0),
                            topLeft: Radius.circular(0)))),
              ))),
    ));
  }
}

Conclusion

To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to customize Flutter textformfield cursor color. I’ll be delighted to receive your feedback on this post.

I’d love to see you visit my other tutorials on Flutter app development and Python programming as well. Thank you for reading this post.

Leave a Comment

Your email address will not be published.