Skip to content

Accessing context / creating snackbars #191

Closed Answered by GregoryConrad
luckyrat asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! 👋

Capsules form a graph of business logic and app/global-level state, so naturally they don't have a BuildContext or some other means to access the UI directly. UI code is separated cleanly via flutter_rearch with RearchConsumers. Thus, you have to go to UI code to change the UI.

You have a few options here, in order of preference/testability:

  1. Make a new RearchConsumer to show the app state as a part of itself (this could even be a SnackBar that you animate yourself, but often you use a more custom widget).
  2. Snackbars are often for user-triggered events (which are often better suited by use.mutation anyways, read on). In this case, you can do:
onPressed: () async {
  await myAsyncFun…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@GregoryConrad
Comment options

@luckyrat
Comment options

@GregoryConrad
Comment options

@luckyrat
Comment options

@GregoryConrad
Comment options

Answer selected by GregoryConrad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants