컨테이너 안의 컨테이너

김인범's avatar
Jan 13, 2025
컨테이너 안의 컨테이너
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: HomePage(), ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Container( width: 100, height: 100, decoration: BoxDecoration( border: Border.all(), borderRadius: BorderRadius.circular(50), ), child: Align( // << Align 을 부모로 변경해서 크기가 따로 설정할 수 있게 됐다. child: Container( // 1. 자식은 부모의 크기를 따라간다. => 80으로 지정했지만 100으로 설정된 모습이다. width: 80, height: 80, decoration: BoxDecoration( borderRadius: BorderRadius.circular(40), color: Colors.red, ), ), ), ) ], ), ); } }

부모 크기가 설정되어 있지 않을 때는 자식 위젯의 크기만큼 설정된다.

1. Align 사용

※ Align을 통해 자식 위젯이 공간을 확보했다면 아래와 같이 정상적으로 자신의 크기를 가진다.
notion image

2. Align 사용 X

notion image
단순히 Container(자식) 위젯만 있을 때는 아래와 같이 나온다.
notion image
부모 컨테이너보다 크기를 작게 설정했지만, 부모 위젯의 크기를 따라가는 모습을 볼 수 있다.
Share article

taker