Menu
CoddyTech

Alinear dentro de una caja

Parte de la sección Diseños que se adaptan del Journey de Flutter de Coddy. Lección 12 de 30.

Center coloca a su hijo en el centro del espacio que tiene. Align hace lo mismo en cualquier lugar que elijas:

Container(
  height: 200,
  color: Colors.teal,
  child: const Align(
    alignment: Alignment.topRight,
    child: Text('Top right'),
  ),
)

Los lugares reciben su nombre de las esquinas y los bordes: Alignment.topLeft, topCenter, topRight, centerLeft, center, centerRight, bottomLeft, bottomCenter y bottomRight. Center es Align con Alignment.center.

Un Stack también acepta un alignment:, que coloca a todos los hijos que no son Positioned: Stack(alignment: Alignment.bottomCenter, children: [...]).

challenge icon

Desafío

Fácil

Mueve el título Mountains desde el centro de la portada hasta la esquina inferior izquierda. El relleno lo mantiene a 16 píxeles de ambos bordes.

Pruébalo tú mismo

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(title: const Text('Travel')),
        body: Column(
          children: [
            Container(
              height: 240,
              color: Colors.indigo,
              child: const Center(
                child: Padding(
                  padding: EdgeInsets.all(16),
                  child: Text(
                    'Mountains',
                    style: TextStyle(fontSize: 28, color: Colors.white),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
quiz iconPonte a prueba

Esta lección incluye un breve cuestionario. Empieza la lección para responderlo y registrar tu progreso.

Todas las lecciones de Diseños que se adaptan

Practica por tu cuenta: Compilador de Flutter online