[Flutter] 레이아웃
SafeArea
- iPhone 노치와 같이 물리적인 레이아웃에 의해 상단바 등이 가리게 될때 사용하기 좋은 클래스
- 잘못된 예
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('Hello world'),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Text('Hello world'),
),
);
}
Center
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Hello world'),
),
);
}
Padding
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
child: Text('Hello world'),
padding: EdgeInsets.fromLTRB(100.0, 300.0, 10.0, 40.0),
),
);
}
Container
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Container'),
),
body: Container(
color: Colors.red,
),
);
}
- Cotainer에 자식 위젯이 할당되면 자식 위젯의 사이즈로 표시된다
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Container'),
),
body: Container(
color: Colors.red,
child: Text(
'Hello world',
style: TextStyle(color: Colors.yellow),
),
),
);
}