inblog logo
|
taker
    플러터

    BoxConstraints

    김인범's avatar
    김인범
    Jan 13, 2025
    BoxConstraints
    Contents
    예시
    BoxConstraints 는 Flutter에서
    레이아웃 시스템에서 제약조건을 나타내는 데 사용되는 클래스입니다.
    UI 구성 요소의 크기를 설정, 제한하는데 사용되는 제약조건을 정의합니다.
     
    주로
    BoxConstraints 위젯의 자식 위젯의 크기를 제한하거나 부모 위젯으로부터 주어진
    제약 조건을 처리할 때, 사용됩니다.
     

    예시

    import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Constraints Example')), body: Center( child: Container( color: Colors.blue, constraints: BoxConstraints( minWidth: 100, minHeight: 100, maxWidth: 300, maxHeight: 300, ), child: Container( // 자식 요소이다. 크기 설정이 부모 BoxConstraints보다 크지만 // 부모요소의 크기보다 커질 수 없다. // 자식 위젯에 크기 설정이 안되어 있다면, 부모 위젯의 최대 크기에 맞춘다. color: Colors.red, //width: 400, //height: 400, //width: 200, //height: 50, child: Center(child: Text('Child')), ), ), ), ), ); } }

    1. Container 크기가 400, 400 일 때

    Container 의 크기 설정은 적용되지 않습니다.
    이유: 상단의 부모 위젯이 Container에 BoxConstraints 로 제약 조건을 걸었기 때문이다.
    notion image
    notion image
     
    Share article

    taker

    RSS·Powered by Inblog