Check out example codes for "flutter textfield with icon onclick". It will help you in understanding the concepts better.

Code Example 1

TextField(
  controller: _controller,
  decoration: InputDecoration(
    hintText: "Enter a message",
    suffixIcon: IconButton(
      onPressed: () => _controller.clear(),
      icon: Icon(Icons.clear),
    ),
  ),
)

Learn ReactJs, React Native from akashmittal.com