[SOLVED] why the height of columns in columns is only for the content?

Issue

This Content is from Stack Overflow. Question asked by hime_chann____

I wrote the following small piece of code to better understand Flutter’s layout system.

class FavoritePage extends HookConsumerWidget {
  const FavoritePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("favorite"),
      ),
      body: Column(
        children: [
          Column(
            children: [Text("hogehoge")],
          ),
        ],
      ),
    );
  }
}

The tree structure of the layout is as follows

enter image description here

enter image description here

However, a question has been raised here.

According to the documentation, the default value of Column’s MainAxisSize is max, so I would expect the height constraint for Column to be the height of the entire screen, but here, the size of the nested interior columns is only for the text display.

Why do these problems occur?



Solution

if you use nested Columns without any Expanded or Flexible, there are no incoming height constraint from the parent Column to the child Column, so the Max setting will be ignored and the height of the nested Column will be height of its children.


This Question was asked in StackOverflow by hime_chann____ and Answered by Julien Joseph Thomas It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?