To supply an initial value to a text field in Flutter, you can set the controller property of the TextField widget to a TextEditingController that contains the initial value. Here's an example:
TextEditingController _controller = TextEditingController(text: 'Initial Value');
TextField(
controller: _controller,
onChanged: (text) {
// Do something when the text changes
},
);
To clear the text field, you can call the clear() method of the TextEditingController instance. For example:
_controller.clear();
This will clear the text in the text field and trigger a redraw.
Alternatively, you can also set the value property of the TextEditingController to a TextEditingValue with an empty string to clear the text. Here's an example:
_controller.value = TextEditingValue(text: '');
This will also clear the text and trigger a redraw.