When I tap on Text Field and write from keyboard then I click done, all data from Text Field was cleared. This is my code:
TextField(
controller: controller,
keyboardType: textInputType,
decoration: InputDecoration(
hintText: hintText,
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.5),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 1,
),
),
),
)
my controller: TextEditingController controller = TextEditingController();
CodePudding user response:
I'm guessing this is a stateless widget, and you're instantiating the TextEditingController in it. Closing the keyboard is causing a rebuild and you're losing the state, and a new controller is being created. You'll want to use a stateful widget and put the TextEditingController in state.