1. 최소 크기에 강제됨
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(
minWidth: 100,
minHeight: 100,
maxWidth: 200,
maxHeight: 200,
),
child: Container(
color: Colors.red,
width: 30,
height: 30,
child: Center(child: Text('Child')),
),
),
),
),
);
}
}
2. 최대 크기에 강제됨
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(
minWidth: 100,
minHeight: 100,
maxWidth: 300,
maxHeight: 100,
),
child: Container(
color: Colors.red,
width: 400,
height: 400,
child: Center(child: Text('Child')),
),
),
),
),
);
}
}
3. 자식에게 크기를 주지 않으면?
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(
minWidth: 100,
minHeight: 100,
maxWidth: 300,
maxHeight: 300,
),
child: Container(
color: Colors.red,
child: Center(child: Text('Child')),
),
),
),
),
);
}
}