sliver_tools
sliver_tools copied to clipboard
New Widget: SliverAlign
SliverAlign is a simple widget which sets its scrollExtent as a fraction of that of its child and then aligns its child within itself along the scroll axis as specified.
SliverClip(
child: SliverAlign(
alignment: AlignmentSliver.center,
mainAxisFactor: 0.5,
child: Container(
height: 100.0,
color: Colors.red,
child: const Placeholder(),
),
),
),
I've mainly created this widget as a way to create custom expansion and collapse animations with slivers and thought it might be a nice addition to this package.
https://user-images.githubusercontent.com/37406743/163694247-e3367de6-f970-45be-a10f-a167a0d7aaa0.mov
Happy for feedback!
@Kavantix Would be great if this lands in master soon :)
@LucasAschenbach first of all thanks for the contribution this would make a fine addition!
In order to merge this I would like a few adjustments/additions:
- Can we rename the alignment to
SliverAlignment - Can you remove any changes that are not needed like some extra whitespace that was added
- I haven’t had time to test it yet but I think this might behave weirdly with child slivers like
SliverPinnedHeadersince you don’t do anything with thepaintOrigin - Can you add some tests for this widget, that way it will be easier to maintain.
Let me know if you need any help/advice and thanks again for contributing!
Thanks for the review!
As for modifying the paint origin: After testing the widget with SliverPinnedHeader, I don't think we should set the child's paint origin to match the top edge of the parent. This would result in all headers sticking to the top during mainAxisFactor animations which is usually not expected. Here is what it currently looks like:
https://user-images.githubusercontent.com/37406743/165527755-90026726-fc88-47f5-addb-365834c1c887.mov
@Kavantix What are your thoughts?
Well the main thing is that I believe adding the align witha main axis factor of 1 should have no effect on the widget.
But currently this is what happens with the align on pull down on iOS:

And
without:
Perhaps take a look at the implementation of SliverAnimatedPaintExtent that should be fairly similar
I also noticed that there are a few hints from the analyzer to improve the code quality, in the final version they'll need to be fixed
@LucasAschenbach did you have any chance to look at it further?