How to find the widget's current size to set the minimum size for the constraints in the Flutter?

227 views Asked by At

I want to know how can I find a widget's default size to set it as constraints: minHeight or constraints: maxHeight properties?

For example if I have this widget:

      Expanded(
        child: Column(
          children: [
            // right menu 1
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  constraints: BoxConstraints(
                    maxHeight: constraints.maxHeight - 16,
                    minHeight: 100,
                  ),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8),
                    color: Colors.blue[400],
                  ),
                ),
              ),
            ),
            // right menu 2
            Expanded(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  constraints: BoxConstraints(
                    maxHeight: constraints.maxHeight - 16,
                    minHeight: 100,
                  ),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8),
                    color: Colors.red[200],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),

And I want to set minHeight to the container's default height instead of hardcoded 100.

1

There are 1 answers

0
venir On

There's a Widget for that

Have you tried LayoutBuilder?