close

How to supply an Initialvalue to TextField Widget in Flutter?

Hello Guys How are you all? Hope You all are fine. I want to supply an initial value to a text field and redraw it with an empty value to clear the text. In this tutorial, we will be learning how to supply an Initialvalue to TextField Widget in a flutter. 

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Error Occurs ?

I want to supply an initial value to a text field and redraw it with an empty value to clear the text.

How to supply an Initialvalue to TextField Widget in Flutter?

  1. How to supply an Initialvalue to TextField Widget in Flutter?

    to supply an Initialvalue to TextField Widget in Flutter. Here we can use TextFormField instead of TextField, and use the initialValue property. for example. Here is how.

  2. supply an Initialvalue to TextField Widget

    to supply an Initialvalue to TextField Widget in Flutter. Here we can use TextFormField instead of TextField, and use the initialValue property. for example. Here is how.

Solution 1: Use a TextFormField instead of TextField

Here we can use TextFormField instead of TextField, and use the initialValue property. for example. Here is how.

TextFormField(initialValue: "Initial Text Value Here");

Solution 2: you can use TextEditingController

TextEditingController myUsernameController = TextEditingController();

@override
void initState() {
  myUsernameController.text = "Initial Text Value Here";
  super.initState();
}

TextField(
  controller: myUsernameController,
  onChanged: (text) => {},
)

Solution 3: TextEditingController then set the text

TextField(
   controller: TextEditingController(text: "Initial Text Value Here"),
)

Summery

So, It’s All About How to supply an Initialvalue to TextField Widget in Flutter?. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: