Development/Flutter - Widget

Flutter 위젯] #29 SizedBox

Clein8 2020. 2. 18. 12:16
반응형

 

 

1) Widget의 크기 지정하기

SizedBox(
  width: 200.0,
  height: 100.0,
  child: FlatButton(
    color: Colors.blue,
    child: Text('Button'),
    onPressed: () {},
  ),
),
SizedBox(
  width: double.infinity,
  height: 100.0,
  child: FlatButton(
    color: Colors.blue,
    child: Text('Button'),
    onPressed: () {},
  ),
),

 

 

2) Widget 간격 설정

주로 Column 사용하면서 위젯간 간격 조절하는데 사용한다. Padding이나 다른걸로 해도 되지만, SizedBox로 하면 heigth만 입력해 주면 되기 때문에 간단하다.

 

Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    FlatButton(
      color: Colors.blue,
      child: Text('Button'),
      onPressed: () {},
    ),
    SizedBox(height: 40),
    FlatButton(
      color: Colors.blue,
      child: Text('Button'),
      onPressed: () {},
    ),
  ],
),

 

 

flutter.dev Reference

 

SizedBox class - widgets library - Dart API

A box with a specified size. If given a child, this widget forces its child to have a specific width and/or height (assuming values are permitted by this widget's parent). If either the width or height is null, this widget will size itself to match the chi

api.flutter.dev

반응형