Flutter

플러터 - 크기 설정

마루설아 2025. 5. 7. 22:31
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 앱 바
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          backgroundColor: Colors.blue,
          elevation: 0,
          shape: Border(bottom: BorderSide(color: Colors.black, width: 2)),
        ),
      ),

      home: Scaffold(
        appBar: AppBar(title: Text('Test')),

        body: Column(
          children: [
            // 위젯 가로 크기를 고정하는 IntrinsicWidth
            IntrinsicWidth(
              child: Column(
                // 아래 crossAxisAlignment를 지정해야만 크기가 가장 큰 위젯의 크기대로 고정됨
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Container(color: Colors.red, width: 50, height: 50.0),
                  Container(color: Colors.green, width: 150.0, height: 150.0),
                  Container(color: Colors.blue, width: 100, height: 100.0),
                ],
              ),
            ),

            // 최소/최대 범위로 크기 고정하는 ConstrainedBox
            ConstrainedBox(
              // 최소 너비 300, 최대 높이 50
              constraints: BoxConstraints(minWidth: 300, maxHeight: 50),
              child: Container(color: Colors.amber, width: 150, height: 150.0),
            ),
          ],
        ),
      ),
    );
  }
}

 

 

'Flutter' 카테고리의 다른 글

플러터 - 텍스트 필드 위젯  (0) 2025.05.14
플러터 - 기타 배치 위젯  (0) 2025.05.08
플러터 - 위치 설정  (0) 2025.04.28
플러터 - 방향 설정  (0) 2025.04.24
플러터 - 컨테이너 및 센터 위젯  (0) 2025.04.15