예시)
Text('Boring')
Container( child: Text('Boring'), color: Colors.blue, );
decoration property를 통해 container의 shape을 추가할 수 있음
import 'package:flutter/material.dart';
class ContainerScreen extends StatelessWidget {
const ContainerScreen({super.key});
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: const Text(
'Container Example',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// 기본 텍스트 위젯 (Container 없음)
const Text(
'Boring',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
// 배경 색만 지정한 Container
Container(
color: Colors.blue,
child: const Text(
'Boring',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
// 패딩이 추가된 Container
Container(
padding: const EdgeInsets.all(20),
color: Colors.blue,
child: const Text(
'Boring',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
// 회전(transform) 효과가 추가된 Container
Container(
transform: Matrix4.rotationZ(0.1),
padding: const EdgeInsets.all(20),
color: Colors.blue,
child: const Text(
'Boring',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
// 원형 모양으로 만들어진 Container
Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.blue,
),
padding: const EdgeInsets.all(20),
child: const Text(
'Boring',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
)
],
),
),
);
}
}