Curso de Flutter: Widgets, Stateless, Stateful, Imagens e Animações
O desafio é o seguinte:
- Quando sua tarefa chegar no nível máximo de maestria (ou seja, a barra de progresso estiver toda preenchida), a tarefa deve MUDAR DE COR.
- Faça vários níveis diferentes de maestria, indicados por diferentes cores!
- Lembre-se de que com dificuldades diferentes, as maestrias demoram mais!
Segue proposta para Desafio Final.
class _TasksState extends State<Tasks> {
int level = 1;
+ bool max = false;
+ int stage = 0;
+ double linearProgressIndicatorValue = 0;
+ List<Color> stageColors = [
+ Colors.blue,
+ Colors.green,
+ Colors.yellow,
+ Colors.orange,
+ Colors.black
+ ];
void levelUp() {
setState(() {
- level++;
+ linearProgressIndicatorValue = (level / widget.dificuldade) / 10;
+ if (linearProgressIndicatorValue >= 1.0) {
+ if (stage >= 3) {
+ stage = 4;
+ max = true;
+ } else {
+ stage++;
+ level = 1;
+ }
+ } else {
+ level++;
+ }
});
}
.....
@@ -33,7 +53,7 @@ class _TasksState extends State<Tasks> {
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
- color: Colors.blue,
+ color: stageColors[stage],
),
height: 140,
),
@@ -126,8 +146,8 @@ class _TasksState extends State<Tasks> {
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
- 'Nivel: $level',
- style: TextStyle(color: Colors.white, fontSize: 16),
+ max ? 'MAX' : 'Nivel: $level',
+ style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],