I'm trying to set an initial value for the text field. But I Can't set the initial value in text form field. I'm getting this error 'initialValue == null || controller == null': is not true
.
code:
Widget buildFirstName(BuildContext context) {
valueBuilder = valueBuild();
return TextFormField(
controller: firstNameController,
initialValue: valueBuilder,
decoration: InputDecoration(
hintText: "Enter Name",
fillColor: Colors.white,
hintStyle: TextStyle(
color: Color.fromRGBO(0, 0, 0, 1.0),
fontFamily: "SFProText-Regular"),
),
validator: validatingName,
);
}
Best Answer
You can't use
initialValue
andcontroller
at the same time. So, a better way is to usecontroller
because its constructor does provide you initial value that you can set.Here is an example.
In order to track the value entered by the user you can then use