Reputation: 1811
I have simplified this question please have a look :---
How can I add OnTap event,ICONS & TITLES to below List view code
ListView.builder(
padding: EdgeInsets.all(10.0),
shrinkWrap: false,
itemCount: 200,
itemBuilder: (BuildContext context, int index) {
return listItem(context, index);
},
Widget listItem(BuildContext context, int index) {
return Card(
child: Row(
children: <Widget>[
Container(margin: EdgeInsets.all(10),child: Text("1")),
Container(height: 20,width: 1,color: Colors.blue,),
Container(margin:EdgeInsets.all(10),child: Text("ram ram ram"))
],
),
);
}
Upvotes: 0
Views: 44
Reputation: 2717
Consider changing your Container
s with ListTile
s, check out the documentation on ListTile. It has an onTap
parameter that you can set in order to trigger a function when a ListTile
is tapped, and it also has leading
, title
, and subtitle
parameters, where you can pass the icons and titles you need.
Another way of adding onTap
detector to any widget is wrapping it with a GestureDetector, or an InkWell, which is basically a GestureDetector
with animations and color effects, roughly speaking. Both GestureDetector
and InkWell
have onTap
parameters that you can use to detect taps and trigger functions.
Upvotes: 1