Вместо того, чтобы делать его переменной, вы можете сделать его методом, а затем передать ему параметр цвета.
Widget buildWidget(Color color) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: color, // Use your color parameter here
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 8.0, 0),
child: ListTile(
title: Text(
message.title),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(message.name),
Row(
children: <Widget>[
Icon(
Icons.alarm_on,
color: Colors.redAccent,
size: 16,
),
Text(message.time),
],
)
],
),
),
),
),
);
}
Вы также можете передать объект сообщения, который используете в качестве параметр функции
Итак, ваш ListView.builder
будет выглядеть так:
ListView.builder(
..., // other properties
itemBuilder: (context, index) => buildWidget(/*Your params here*/),
),