Contents
예제- Container
- min : 0
- max : double.infinity
- 크기를 주지 않고, 자식이 있으면 (자식 크기만큼 줄어듬)
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Constraints Example')),
body: Center(
child: Container(
color: Colors.blue,
constraints: BoxConstraints(
// 1. 부모는 자식에게 제약조건을 전파
minWidth: 0,
minHeight: 0,
maxWidth: double.infinity,
maxHeight: double.infinity,
),
child: Container(
color: Colors.red,
// 2. 자식은 부모의 제약조건 내에서만 동작
// 3. 자식은 크기가 없으면 Max 값을 따름
child: Center(child: Text('Child')),
),
),
),
),
);
}
}
예제
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Constraints Example')),
body: ListView(
children: [
AspectRatio(
aspectRatio: 1 / 1,
child: Image.asset("test.png", fit: BoxFit.cover),
),
],
),
),
);
}
}
Share article