Skip to content

Make GridView child's height wrap by its content #29035

Closed

Description

@SixSheeppp

return Container( height: 100, child: GridView.count( primary: false, crossAxisCount: defaultItemCount, mainAxisSpacing: 0, childAspectRatio: _childAspectRatio, physics: NeverScrollableScrollPhysics(), children: _createChildItemList(data.gridItem), ));

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?

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Mar 11, 2019
  2. cirediew commented on May 7, 2019

    @cirediew

    I agree.

    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: (...)
    
  3. SixSheeppp commented on May 8, 2019

    @SixSheeppp
    Author

    I agree.

    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: (...)
    

    Yes.I handle this just like u.

  4. added this to the milestone on Jan 3, 2020
  5. modified the milestones: , on Jan 7, 2020
  6. changed the title [-]Some improvement ideas of GridView[/-] [+]Make GridView child's height wrap by its content[/+] on Apr 21, 2020
  7. added
    P3Issues that are less important to the Flutter project
    on May 29, 2020
  8. removed this from the milestone on Aug 17, 2020
  9. kutear commented on Mar 23, 2021

    @kutear

    I agree.

    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]

  10. pourqavam commented on Nov 29, 2021

    @pourqavam
    Contributor

    Same issue.

  11. Piinks commented on Jul 11, 2022

    @Piinks
    Contributor

    Closing as a duplicate of #97544. Please follow progress in that issue.

  12. github-actions commented on Jul 25, 2022

    @github-actions

    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.

  13. locked as resolved and limited conversation to collaborators on Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions