concept constraint in category flutter

appears as: constraints, constraints, The constraint, The constraints
Flutter in Action

This is an excerpt from Manning's book Flutter in Action.

After the widget tree is composed, Flutter can start thinking about layout. Flutter walks down the tree—only once—in linear time. (If you aren’t familiar with Big O notation, linear time means fast.) On the way down, it’s collecting information about the position of widgets. In Flutter, layout and size constraints are dictated from parent to child.

Besides layout widgets, I’ll also talk about constraints in Flutter. Constraints are a core part of understanding layout. In a nutshell, though, constraints tell widgets how much space they can take up, and then the widgets decide what they will take up. In section 3.6.2, I talk about constraints in depth.

In other words, constraints are concerned with minWidth, minHeight, maxWidth, and maxHeight. Size, on the other hand, is concerned with actual width and height. When a render box is given its constraints, it then decides how much of that allotted space it will actually take up (its size).

// weather_app/lib/widget/sun_background.dart
class Sun extends AnimatedWidget {
  Sun({Key key, Animation<Color> animation})
      : super(key: key, listenable: animation);         #1
 
  @override
  Widget build(BuildContext context) {
    final Animation<Color> animation = listenable;      #2
    double maxWidth = MediaQuery.of(context).size.width;
    double margin = (maxWidth * .3) / 2;
 
    return AspectRatio(
      aspectRatio: 1.0,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: margin),
        constraints: BoxConstraints(
          maxWidth: maxWidth,
        ),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: animation.value,                       #3
        ),
      ),
    );
}