orlikraf / flutter-hexagon

MIT License
30 stars 17 forks source link

"uneven" grids? #15

Open slovnicki opened 3 years ago

slovnicki commented 3 years ago

Is it possible to have a HexagonOffsetGrid with, for example, 2 rows and 4 columns with a total of 7 HexagonWidgets?

In my project, I'm faking the rest to fill the incomplete row, something like this:

// in HexagonOffsetGrid
rows: (myItems.length / columns).ceil();
buildChild: (col, row) {
  if (row * columns + col >= myItems.length) {
   return Container();
  }
  return MyHexagonWidget(
    myItem: myItems[row * columns + col];
  );
orlikraf commented 3 years ago

Sorry for late response. I understand that you want to hide the hex at position. In addition to what you have provide buildTile function with transparent hex like this:

buildTile: (col, row) {
  if (row * columns + col >= myItems.length) {
   return HexagonWidgetBuilder(color: Colors.transparent);
  }
  return HexagonWidgetBuilder();
}

This was added in version 0.7

slovnicki commented 3 years ago

@orlikraf is this something you would like to be handled internally? (I can try to make a PR sometime this week) For example, to provide a count to HexagonOffsetGrid and then have it call these builders just for count times, removing the need for users to check if (row * columns + col >= count)

orlikraf commented 3 years ago

This could be useful. Feel free to create a PR and I will check is when I find time. I wonder if HexagonOffsetGrid should get additional named constructors that takes new builder function based on count parameter or alternatively accepting an array of widget children which would nicely translate to count as well.

akshay-appinventiv commented 3 years ago

Hi any update on this? I'm looking for something like this which basically focus on total no hexagon.

slovnicki commented 3 years ago

I didn't have time to work on this.

@orlikraf At first glance, can we just add a nullable count property, add it to all named constructors and then do

if (count != null && row * this.columns + col > count) {
  return SizedBox.shrink();
}

here https://github.com/rSquared-software/flutter-hexagon/blob/e3bf84bb52496a0e72199bdbfedf72635d0da9c3/lib/src/grid/hexagon_offset_grid.dart#L256

orlikraf commented 3 years ago

I if have time next week I will try your suggestion.