jamesblasco / modal_bottom_sheet

Flutter | Create advanced modal bottom sheets. Material, Cupertino or your own style
https://pub.dev/packages/modal_bottom_sheet
MIT License
1.83k stars 461 forks source link

add Sheet.addPostLayoutCallback static method #413

Open vishna opened 1 week ago

vishna commented 1 week ago

What is this PR about?

Addresses issue #412, adds the Sheet.addPostLayoutCallback which allows to defer SheetController calls.

Why do I need this?

Expanding Sheet using SheetController might not always work, e.g. you are trying to animate the sheet and expand controller at the same time (see: https://github.com/jamesblasco/modal_bottom_sheet/issues/412). You can use addPostLayoutCallback in order to defer your call to the moment RenderSheetViewport has finished RenderSheetViewport.performLayout Additionally you can provide timeout after which this callback should be called anyway incase RenderSheetViewport.performLayout doesn't start. Usually (this has not been super benchmarked!) layout starts under 50ms, putting 100ms to be on the safe side - YMMV

Sidenote

This is the best solution I could come up with, studying all the complexities of this package. This still doesn't fix the core issue, which is performing layout and expanding sheet at the same time - which just ends with setPixels(0.0) (as shown in the bug report). This PR adds rather ugly static method that provides a bit more reliable workaround than use of Future.delay.