google / flutter.widgets

https://pub.dev/packages/flutter_widgets
BSD 3-Clause "New" or "Revised" License
1.37k stars 479 forks source link

ItemPosition doesn't give enough information #97

Open marcglasberg opened 4 years ago

marcglasberg commented 4 years ago

The is the current provided information:

const ItemPosition( {@required this.index, @required this.itemLeadingEdge, @required this.itemTrailingEdge});

This is not nearly enough for all kinds of applications. For example, with the above info I can't implement a multi-item sticky-headers.

It should be:

  const ItemPosition(
      {@required this.index,
      @required this.leadingAlignment,
      @required this.trailingAlignment,
      @required this.leadingPixelDistance,
      @required this.trailingPixelDistance,
      @required this.length,
});

Also, how can I get the length of the viewport?

tarobins commented 4 years ago

Can you define each of the items proposed below?

const ItemPosition( {@required this.index, @required this.leadingAlignment, @required this.trailingAlignment, @required this.leadingPixelDistance, @required this.trailingPixelDistance, @required this.length, });

How would you be using these to implement something like https://pub.dev/packages/sticky_headers?

marcglasberg commented 4 years ago
marcglasberg commented 4 years ago

I edited the issue to remove the reference to https://pub.dev/packages/sticky_headers. In fact, that package in particular does work for ScrollablePositionedList, because ScrollablePositionedList uses two regular scrolls, and that StickyHeaders can get the necessary pixel position from these.

In any case, there are other uses for knowing the exact pixel distances, instead of only the alignment. For example, I want to create another kind of StickyHeader that spans multiple items.

This is what I am trying to do to implement a sticky header in a vertical scroll:

  1. Put the list inside of a Stack.
  2. When the leadingPixelDistance of the item at the top is positive or zero, I don't and a header to it.
  3. When the leadingPixelDistance is negative (meaning that part of the item is out of the screen), I add the header. This means the header will start to overlap the content.
  4. When the item is going out of the screen, so that the header doesn't fit anymore, the header needs to start moving out as well, by the same number of pixels.

I can't do that without the pixel information.