Container
는 자식 위젯을 한개 포함하며, 크기를 지정할 수 있다.
크기를 지정하지 않으면 자식 위젯의 크기에 맞춰지고, 자식 위젯이 없거나 크기가 지정되어 있지 않으면 width와 heighnt은 최대값으로 고정된다.
UI커스텀 하기 좋다.
Container의 decoration 속성에 BoxDecoration위젯을 주면 Container를 꾸밀 수 있다.
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
),
child: Text('Main'),
)
)
);
}
}
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
image: DecorationImage(
image: AssetImage(
'images/flutter1.png'
)
)
),
child: Text('Main'),
)
)
);
}
}
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
border: Border.all(
color: Colors.black,
style: BorderStyle.solid,
width: 10
)
),
child: Text('Main'),
)
)
);
}
}
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle
),
child: Text('Main'),
)
)
);
}
}
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10.0)
),
child: Text('Main'),
)
)
);
}
}
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(10)
)
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.red,
Colors.blue,
]
)
),
child: Text('Main'),
)
)
);
}
}
colors: [
Colors.red,
Colors.yellow,
Colors.green,
Colors.blue,
],
stops: [0.1, 0.4, 0.6, 0.9]
class MainPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 150,
width: 150,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 5.0,
spreadRadius: 3.0,
),
],
),
child: Text('Main'),
)));
}
}
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 5.0,
spreadRadius: 3.0,
offset: Offset(
3,
3,
)),
]
clipbehavior
를 사용하면 자식이 범위 밖을 지나면 자동으로 잘라준다