Issue
I have unknown list data fetch from API. Here is my code where I declared random color for the list view.
Widget employeeListBuilder() {
return Scrollbar(
isAlwaysShown: true,
thickness: 6,
radius: const Radius.circular(10),
child: ListView.builder(
itemCount: employee.length,
itemBuilder: (context, i) {
return ListViewWidget(
name: employee[i].name.toString(),
department: employee[i].department.toString(),
color: Colors.primaries[Random().nextInt(Colors.primaries.length)] ,
);
},
),
);
}
Solution
Try to use below code hope its help to you. Refer Primaries-Constant
color: Colors.primaries[i % Colors.primaries.length],
Answered By - Ravindra S. Patil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.