Here i have created a simple demo for using color shade of Color variable
I have a container with a color and and a center text which color should be lighter shade of container’s color
here is my code
List<Color> colorlist=[
Colors.red,
Colors.orange,
Colors.greenAccent,
Colors.blue,
Colors.yellow,
];
class HomeScreen6 extends StatelessWidget {
const HomeScreen6({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: colorlist.length,
itemBuilder: (context,index){
return Container(
height: 100,
width: double.infinity,
color: colorlist[index],
child: Center(
child: Text('Sample',style: TextStyle(
color: colorlist[index].shade200,//here i want light shade of container's color
),),
),
);
}),
);
}
}
2
Answers
I am suggested following code but i dont think its a good way of coding
Just change your list from
List<Color>
toList<ColorSwatch>
, and then style yourText
widget like this:Btw
Colors.greenAccent
is not a validColorSwatch
value.