Skip to content

fix(snackbar): ensure deferred custom snackbar is shown after async gap - #47

Open
Eimen2018 wants to merge 3 commits into
mainfrom
fix/1163-custom-snackbar-after-async-gap
Open

Eimen2018 wants to merge 3 commits into
mainfrom
fix/1163-custom-snackbar-after-async-gap

Conversation

@Eimen2018

Copy link
Copy Markdown
Collaborator

Summary

Fixes Stacked-Org/stacked#1163: showCustomSnackBar silently did nothing when called after an await (for example after a delayed API call) instead of from a tap handler or build.

Root cause

SnackbarConfig.instantInit defaults to false. On that path showCustomSnackBar defers getBar.show() to WidgetsBinding.addPostFrameCallback. That callback only runs when the engine next produces a frame. After an async gap with nothing else pending, the binding is idle and no frame is ever scheduled, so the callback never fires and the snackbar never appears. The "two snackbars on a delayed re-tap" from the issue is the same bug: queued callbacks pile up and all fire when an unrelated frame finally runs.

Fix

Call binding.ensureVisualUpdate() right after registering the post-frame callback. It schedules a frame when the binding is idle and is a no-op while a frame is already underway, so the existing "defer until after the current build" behaviour of instantInit: false is unchanged.

Tests

test/snackbar_service_test.dart (new):

  • Reproduces the issue: with an idle scheduler, showCustomSnackBar now schedules a frame and the snackbar renders. Verified this test fails on main without the fix.
  • Regression guard for instantInit: true.

Notes

  • No change to the get dependency (the removal in refactor: remove the get dependency #46 can proceed independently) and no public API change.
  • flutter test: 3 passed. dart analyze lib test: no new issues.

🤖 Generated with Claude Code

Eimen2018 and others added 2 commits September 18, 2026 01:48
showCustomSnackBar deferred the show to a post-frame callback but never scheduled a frame, so when called after an await with no pending frame the snackbar never appeared.

Fixes Stacked-Org/stacked#1163

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
dialog_service.dart and example dialog_view.dart were already unformatted on main and fail the Verify Format step for every PR. No code change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Eimen2018

Copy link
Copy Markdown
Collaborator Author

CI note: the Verify Format failure was pre-existing. dart format --set-exit-if-changed . on main already flags lib/src/dialog/dialog_service.dart and example/lib/ui/views/dialog_view.dart, so every PR fails that step. Added a separate chore commit formatting those two files so this PR can pass. No code change in that commit.

@Eimen2018
Eimen2018 force-pushed the fix/1163-custom-snackbar-after-async-gap branch from 3ef0817 to b38529d Compare September 17, 2026 21:49
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@ferrarafer ferrarafer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: showCustomSnackBar doesn’t display

2 participants