'Flutter: Preventing size change to child widgets in GridView

I have code that uses GridView to create a list of items with number of columns based on devices orientation or width.

GridView.count(
  crossAxisCount: columnCount(context),
  childAspectRatio: 8.0,
  padding: const EdgeInsets.all(4.0),
  mainAxisSpacing: 10.0,
  crossAxisSpacing: 10.0,
  children: <Widget>[...textsWidgets],
);

The problem is, the children (textsWidgets) changes size upon resizing the window of the application during runtime. Is there a way to prevent children from changing size when resizing the window of the application during runtime?



Solution 1:[1]

You can simply wrap a GridView with ConstrainedBox to prevent it from growing with the window, like:

ConstrainedBox(
  constraints: BoxConstraints(maxWidth: 320),
  child: GridView.count(…),
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcin Wróblewski