Flutter Get the widget size before render

Mhammad Attar
Sep 7, 2023

--

Sometimes you need to know the available width or height before you render a list of items like Images or something else, one of the best methods to do that is using the Expanded widget and the LayoutBuilder class that builds a widget tree that can depend on the parent widget’s size.
Note that you need LayouBuilder using Expanded in order to get the available width or height

    Expanded(child: LayoutBuilder(builder: (context, constraints) {

var width = constraints.constrainWidth();
var height =constraints.constrainHeight();
.......
}));

I appreciate your taking the time

--

--