1
resposta

[Projeto] Desafio Resolvido

import 'package:flutter/material.dart';

class Task extends StatefulWidget {
  const Task({
    Key? key,
    required this.nome,
    required this.image,
    required this.dificuldade,
  }) : super(key: key);

  final String nome;
  final String image;
  final int dificuldade;

  @override
  State<Task> createState() => _TaskState();
}

class _TaskState extends State<Task> {
  int nivel = 0;
  int levelColor = 0;
  final Map<int, Color> colorMap = {
    1: Color.fromARGB(255, 1, 45, 165),
    2: Color.fromARGB(255, 79, 33, 243),
    3: Color.fromARGB(255, 84, 2, 190),
    4: Color.fromARGB(255, 41, 0, 68),
    5: Colors.black,
  };
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Stack(
        children: [
          Container(
            color: colorMap[levelColor] ?? Colors.blue,
            height: 140,
          ),
          Column(
            children: [
              Container(
                color: Colors.white,
                height: 100,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                      color: Colors.black26,
                      width: 72,
                      height: 100,
                      child: Image.network(
                        widget.image,
                        fit: BoxFit.cover,
                      ),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          width: 250,
                          child: Text(
                            widget.nome,
                            style: const TextStyle(
                              fontSize: 24,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                        Difficulty(widget.dificuldade),
                      ],
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: SizedBox(
                        height: 50,
                        width: 80,
                        child: ElevatedButton(
                          onPressed: () {
                            setState(() {
                              if (levelColor < 6) {
                                nivel++;
                              }
                            });
                            if (((nivel / widget.dificuldade) / 10) > 1) {
                              levelColor++;
                              nivel = 0;
                            }
                          },
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.blue,
                          ),
                          child: const Column(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              Icon(
                                Icons.arrow_drop_up,
                                color: Colors.white,
                              ),
                              Text(
                                "Up",
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: SizedBox(
                      width: 200,
                      child: LinearProgressIndicator(
                        value: (nivel / widget.dificuldade) / 10,
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "Nível $nivel",
                      style: const TextStyle(
                        color: Colors.white,
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
1 resposta

Oii, tudo bem?

Geovanna, seu trabalho com a implementação das cores dinâmicas para as tarefas concluídas ficou ótimo! A abordagem de mapeamento de cores foi bem pensada e a lógica de atualização funcionou perfeitamente. Continue assim!

Um abraço e bons estudos.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software