I have a listTile builder that returns this listTile. The color of the listTile, white, is overwritten by its parent. How do I stop this?
return ListTile(
key: Key(index.toString()),
tileColor: Colors.white,
title: Text(widget.userExercises[index].name),
subtitle: Text("${widget.userExercises[index].reps} Reps"),
trailing: Text("${widget.userExercises[index].sets} Sets"),
onTap: () => widget.editFunction(widget.userExercises[index]),
);
However, when I run my app, the tileColor is overwritten by the parent Container’s color.
return Container(
alignment: Alignment.center,
color: Colors.lightBlue,
child: ExerciseTable(
userExercises: todaysExercises,
editFunction: _showEditDialog,
),
);
Resulting in the following:
Thank you! (and sorry for the image size I don’t know how to change it)
3
Answers
I am surprised, when I looking at this issue. Wrap the
ListTile
withMaterial
will solve the issue, but still I’m not sure how issue is happening.ListTile
paints itstileColor
on aMaterial
widget ancestor. When a coloredContainer
is in between theListTile
and that ancestor you won’t see thetileColor
. To quote from here https://github.com/flutter/flutter/pull/86355/commits/9341a6b1d0d2852ee3c7eb413bbbdc9327f425c8 :See also this discussion: https://github.com/flutter/flutter/issues/83108
Warp the ListTile with Material widget because tileColor is not painted by the ListTile widget itself but by the material widget.