1
resposta

Faça como eu fiz: o retorno do Widget

Insira aqui a descrição dessa imagem para ajudar na acessibilidade


class ColorfulBlocksRow extends StatefulWidget {
  const ColorfulBlocksRow({Key? key}) : super(key: key);

  @override
  State<ColorfulBlocksRow> createState() => _ColorfulBlocksRowState();
}

class _ColorfulBlocksRowState extends State<ColorfulBlocksRow> {
  Color color1 =
      Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
  Color color2 =
      Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
  Color color3 =
      Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Container(
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black,width: 2.0, style: BorderStyle.solid),
                borderRadius: BorderRadius.circular(8),
                color: color1,
              ),
              width: 100,
              height: 150,
            ),
            Container(
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black,width: 2.0, style: BorderStyle.solid),
                borderRadius: BorderRadius.circular(8),
                color: color2,
              ),
              width: 100,
              height: 150,
              child: const Icon(Icons.group),
            ),
            Container(
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black,width: 2.0, style: BorderStyle.solid),
                borderRadius: BorderRadius.circular(8),
                color: color3,
              ),
              width: 100,
              height: 150,
            ),
            ElevatedButton(
                onPressed: () {
                  setState(() {
                    color1 =
                        Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
                            .withOpacity(1.0);
                    color2 =
                        Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
                            .withOpacity(1.0);
                    color3 =
                        Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
                            .withOpacity(1.0);
                  });
                },
                child: const Icon(Icons.change_circle)),
          ],
        ),
      ),
    );
  }
}
1 resposta

Fala Vinicius de boa ?

Cara sua solução ficou bem boa e clara para entender o que tá rolando e o resultado da ui entrega bem o que deveria ser feito, parabens !

Ficou com alguma dúvida enquanto fazia ? Se sim fala pra gente, vai ser super legal te ajudar :)