I’m pretty new to this and I’m a bit stumped. Trying to have various background colours on gridView items but all the ways I know of don’t seem to work, because the data is coming from firebase.
var colors = [
Colors.red,
Colors.blue,
Colors.cyan,
Colors.green,
Colors.yellow,
];
Widget gridPost(
String Name,
String JobTitle,
String Company,
String photo,
) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
color: colors[index]
)),}
This doesn’t work because of the ‘index’ part of colors[index]. if I add int index to the gridPost widget, it then wants it also as
return gridPost(
snapshot.data!.docs[index]['index'],)
but that doesn’t work either because that doesn’t exist in Firebase. adding a dummy field to firebase also didn’t work. Please help 🙂
This is more or less what I’m after
2
Answers
Try to create a method like this :
call method like this :
if you want to create random color and use it in the background you can do it like this
EDIT
if you want to select from the list try this code: