You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make GridView child's height wrap by its content #29035
Its the usual way to create a gridview.
But what makes me confused is the child item's height of the gridview is not determined by the child height.Its measured by the childAspectRatio. Is there any way to make child's height wrap by its content?
I solved this for now by doing the following in Widget build(BuildContext context):
var maxWidth = 500.0;
var width = MediaQuery.of(context).size.width;
var columns = (width ~/ maxWidth) + 1;
var columnWidth = width / columns;
//136 is the height of one grid item
var aspectRatio = columnWidth / 136;
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxWidth, childAspectRatio: aspectRatio),
delegate: (...)
I solved this for now by doing the following in Widget build(BuildContext context):
var maxWidth = 500.0;
var width = MediaQuery.of(context).size.width;
var columns = (width ~/ maxWidth) + 1;
var columnWidth = width / columns;
//136 is the height of one grid item
var aspectRatio = columnWidth / 136;
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxWidth, childAspectRatio: aspectRatio),
delegate: (...)
I solved this for now by doing the following in Widget build(BuildContext context):
var maxWidth = 500.0;
var width = MediaQuery.of(context).size.width;
var columns = (width ~/ maxWidth) + 1;
var columnWidth = width / columns;
//136 is the height of one grid item
var aspectRatio = columnWidth / 136;
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxWidth, childAspectRatio: aspectRatio),
delegate: (...)
but sometime we can't measure the height of grid item [cry]
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
cirediew commentedon May 7, 2019
I agree.
I solved this for now by doing the following in
Widget build(BuildContext context):SixSheeppp commentedon May 8, 2019
Yes.I handle this just like u.
[-]Some improvement ideas of GridView[/-][+]Make GridView child's height wrap by its content[/+]kutear commentedon Mar 23, 2021
but sometime we can't measure the height of grid item [cry]
pourqavam commentedon Nov 29, 2021
Same issue.
Piinks commentedon Jul 11, 2022
Closing as a duplicate of #97544. Please follow progress in that issue.
github-actions commentedon Jul 25, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.