Open vishna opened 1 week ago
Made a PR that allows firing exactly when the layout is done using Sheet.addPostLayoutCallback
:
setPage(1);
Sheet.addPostLayoutCallback(() async {
await sheetController.relativeAnimateTo(
1,
duration: const Duration(milliseconds: 400),
curve: Curves.easeOutQuart,
);
setPage(0);
});
This can still fail if the widget in your sheet causes RenderSheetViewport
trigger performLayout
more than once. We had this issue in our main app but solved this by optimizing how we build our widget tree.
The best fix would be for the animation to always complete, treat my PR as a workaround that might not work for you.
What's wrong
Calling
SheetController.relativeAnimateTo
does nothing in conditions where it should expandSteps to repro
Here's the "minimal" code I managed to put together to illustrate the issue
Launch simulator, press FAB button and watch the sheet not appear. If you switch in code from // BAD to // GOOD, hot restart, tap the button again the sheet will appear 😐
What's happening
BAD CASE
GOOD
What I think is happening
Whenever
animateTo
is called and a new widget is put at the same time, aperformLayout
insideRenderSheetViewport
will have to be called. In GOOD case this manages to happen beforebeginActivity(IdleScrollActivity#2b86b)
so the sheet "knows" how to expand. In BAD CASE out widget seems to be more complex and the dimensions are not delivered on time and the animation doesn't execute properly.I managed to workaround this by putting a delay of
150ms
beforeanimateTo
. This is obviously a non ideal HACK. Other possible hack is to use "Placeholder" widget and only replace the widget once the animation is ongoing. Related -> https://github.com/jamesblasco/modal_bottom_sheet/issues/360Investigating a proper fix, if anyone has any pointers - let me know.