What is the best practice to adapt the number of columns (crossAxisCount) of a GridView based on its width in Flutter?
Maybe I can better explain the intended behaviour by referencing HTML:
Use Wrap. It can put renderboxes as many as fit to a row, then wrap to the next row. (formerly a comment, but it looks like the answer!)
I do this like below. You can try..
int getItemCountPerRow(BuildContext context) {
double minTileWidth = 200; //in your case
double availableWidth = MediaQuery.of(context).size.width;
int i = availableWidth ~/ minTileWidth;
return i;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.