class _TaskState extends State<Task> {
int nivel = 0;
int lvl_color_task = 0;
Color color_task = Colors.blue;
@override
Widget build(BuildContext context) {
double progresso =
(widget.dificuldade > 0) ? (nivel / widget.dificuldade) / 10 : 1;
setState(() {
(progresso > 1 && lvl_color_task < 6)
? (
nivel = 1,
progresso = (nivel / widget.dificuldade) / 10,
lvl_color_task++
)
: null;
switch (lvl_color_task) {
case 0:
null;
case 1:
color_task = Colors.green;
case 2:
color_task = Colors.yellow;
case 3:
color_task = Colors.orange;
case 4:
color_task = Colors.red;
case 5:
color_task = Colors.pink;
case >= 6:
color_task = Colors.black;
}
});
return Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: [
ColorTask(
color: color_task,
),
...
);
}
}
class ColorTask extends StatelessWidget {
final color;
const ColorTask({super.key, required this.color});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: color,
),
height: 140,
);
}
}