Flutter List View Ripple Effect Doesn't Work
185
Solution 1
For the InkWell
ripple effect, try wrapping the InkWell
in a Material
widget.
Material(
child: InkWell(
onTap: () {
print(showroomModel[index]);
},
child: ListTile(
title: Text(showroomModel[index]),
),
),
)
For the separator use ListView.separated
as in Tasnuva oshin's answer.
As pointed out by TheFabbius, the above code can also be simplified by removing the InkWell
and moving the onTap
inside the ListTile
.
Material(
child: ListTile(
onTap: () {
print(showroomModel[index]);
},
title: Text(showroomModel[index]),
),
)
Solution 2
For Separator & Ripple Effect Use
ListView.separated(
itemCount: 25,
separatorBuilder: (BuildContext context, int index) => Divider(height: 1),
itemBuilder: (BuildContext context, int index) {
return Inkwell(child:
ListTile(
title: Text('item $index'),
));
},
);
Author by
Ömer Faruk Arslan
Updated on January 02, 2023Comments
-
Ömer Faruk Arslan over 1 year
I have a ListView in AlertDialog container. There is an InkWell method but ripple effect doesn't work and I can't put the separator. How can I put separator and have ripple effect?
Widget setupAlertDialoadContainer(context) { return Container( color: Colors.white, height: 300.0, width: 300.0, child: ListView.builder( itemCount: showroomModel.length, itemBuilder: (BuildContext context, int index) { return InkWell( onTap: () => { print(showroomModel[index]), }, child: ListTile( title: Text(showroomModel[index]), ), ); }), );
}
-
Ömer Faruk Arslan over 2 yearsThe Separator part is working but still there is no Ripple Effect .
-
Ömer Faruk Arslan over 2 yearsI add this: return Material ( child: InkWell( //code here )); and it work.
-
TheFabbius almost 2 yearsMaybe it's worth noting that
InkWell
is not needed in this case, as theMaterial
widget is enough and theonTap
callback can be moved intoListTile
. -
mmcdon20 almost 2 years@TheFabbius good catch, I have updated the answer to show your suggestion.