1
resposta

Resolução do exercício 02. Widgets - exercício 07

import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    const double squareSize = 100;
    return MaterialApp(
      title: 'Flutter Demo',
      color: Colors.blue,
      home: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          MyAppRow(
                  squareSize: squareSize,
                  color1: Colors.red,
                  color2: Colors.amber,
                  color3: Colors.yellow)
              .row(),
          MyAppRow(
                  squareSize: squareSize,
                  color1: Colors.green,
                  color2: Colors.cyan,
                  color3: Colors.blue)
              .row(),
          MyAppRow(
                  squareSize: squareSize,
                  color1: Colors.purple,
                  color2: Colors.pink,
                  color3: Colors.white)
              .row(),
        ],
      ),
    );
  }
}

class MyAppRow extends Row {
  MyAppRow({
    required this.squareSize,
    required this.color1,
    required this.color2,
    required this.color3,
  });

  final double squareSize;
  final Color color1;
  final Color color2;
  final Color color3;

  Row row() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Container(
          width: squareSize,
          height: squareSize,
          color: color1,
        ),
        Container(
          width: squareSize,
          height: squareSize,
          color: color2,
        ),
        Container(
          width: squareSize,
          height: squareSize,
          color: color3,
        ),
      ],
    );
  }
}

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

1 resposta

WOWWWW Que genial!!

Adorei que você criou uma classe que extende o Widget Row para criar os componentes!

Isso torna seu código muito reutilizável e dinâmico, gostei de ver!!

Continue assim Daniel c: