I have a TextField which has an attribute prefixIcon that accepts a widget. I passed a GestureDetector so that I can do something onTap event of it. But the problem I am facing is as soon as I tap it, though it calls onTap event it but along with that it also focussed the TextField that further launches the keyboard.
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body:MyWidget,
);
}
}
class MyWidget extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return MyWidgetState();
}
}
class MyWidgetState extends State<MyWidget>
{
@override
Widget build(BuildContext context) {
return Container(
height: 200,
width: 200,
padding: EdgeInsets.all(20),
child: TextField(
decoration: InputDecoration(
prefixIcon: GestureDetector(
child: Container(color: Colors.greenAccent, width: 25, height: 25,),
onTap: () => print("hmm"),
),
),
),
);
}
}
So I am trying to find a way by which tapping on prefixIcon widget (here GestureDetector doesn't focus TextField). How can I achieve that functionality?