Development/Flutter - Widget

Flutter Widget] #02 Expanded

Clein8 2020. 3. 19. 18:46
반응형

Flutter Widget #02 Expanded

Widget of the Week #2 Expanded

 

Flutter Widget #02 Expanded

  Expanded의 대표적인 기능은 이름에서 알 수 있듯이 확장 시키는 것이다. Column이나 Row Widget의 마지막에 Expanded를 넣어주면 나머지 여백을 전부 채운다.

 

 

Flutter Widget #02 Expanded - Flex

  두번째는 Flex이다. Expanded는 Flex 속성값을 설정 할 수 있어서 Widget의 크기를 비율로 조정할 수 있다. html5에서와 같은 기능을 한다.

 

 

 

cf) Row 안에 TextField를 그냥 넣으면 console 창에 다음과 같은 메시지를 볼 수 있다. 사이즈가 어쩌고 저쩌고...

'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'

  근데, TextField를 Expanded로 감싸주면 에러가 사라진다.

 

 

flutter.dev Reference

 

Expanded class - widgets library - Dart API

A widget that expands a child of a Row, Column, or Flex so that the child fills the available space. Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space along the main axis (e.g., horizontally for a Row or ve

api.flutter.dev

반응형