flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.23k stars 27.26k forks source link

GridView: support auto size and colspan #149659

Open javaone199 opened 4 months ago

javaone199 commented 4 months ago

Use case

All cells of a GridView have the same size(width x height). It is not suitable for some use cases. For example, For displaying an employee info:

      Name:             John Tigger
     ------------------------------------------------------
     Address:         123 Hello Street
                             New City, New State 123456
                             New Country
     ------------------------------------------------------
     Show a map for the address (colspan: 2)
     ------------------------------------------------------
     Manager:          Mike Tigger
     ------------------------------------------------------
     Performance:     9/10
     ------------------------------------------------------

1). The property name column occupies less space than value column. So cell width should be auto. 2). All cell heights need to be auto. Auto: fit content. 3). Map occupies a whole row (colspan: 2).

In html, they can be achieved by the following css:

.grid {
    display: grid;
    grid-template-columns: auto auto;
}

.map-cell {
   grid-column-end: span 2;
}

Proposal

Add attribute "cellSize" to GridView, and add a new class GridCell that supports colspan attribute. For example,

   GridView.count(
      crossAxisCount: 2,
      cellSize: auto,
      children: [
           Widget1, Widget2
           GridCell(colspan: 2, child: widget),
      ],
    );
moffatman commented 4 months ago

Table() supports the column sizing you want through use of IntrinsicColumnWidth(). No ColSpan though... https://github.com/flutter/flutter/issues/21594

I think maybe the new https://pub.dev/packages/two_dimensional_scrollables package can have all your features though within TableView()?

darshankawar commented 4 months ago

I think maybe the new https://pub.dev/packages/two_dimensional_scrollables package can have all your features though within TableView()?

This sounds like proposal for the package @moffatman.

I'll keep this issue open as proposal.