when i read the Container layout behavior of Container document:
If the widget has no child, no height, no width, no constraints, and the parent provides unbounded constraints, then Container tries to size as small as possible.
so i write some code like below ,i think the second container should be as small as possible,but it fill the application’s content area (the entire screen) ,why?
class ContainerWithScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Container with scaffold',
home: Scaffold(
body: Container(
color: Colors.blue,
height: double.infinity,// provides unbounded height constraints for the child container
width: double.infinity,// provides unbounded width constraints for the child container
child: new Container(
color: Colors.white,
),
),
),
);
}
}
You set a height and width, try using UnconstrainedBox
Container(
color: Colors.blue,
height: double
.infinity, // provides unbounded height constraints for the child container
width: double
.infinity, // provides unbounded width constraints for the child container
child: UnconstrainedBox(
child: new Container(
color: Colors.red,
),
),
),
More info : https://docs.flutter.io/flutter/widgets/UnconstrainedBox-class.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With