Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling in MomentumBuilder #12

Closed
jezer07 opened this issue Jun 24, 2020 · 2 comments
Closed

Error handling in MomentumBuilder #12

jezer07 opened this issue Jun 24, 2020 · 2 comments

Comments

@jezer07
Copy link

jezer07 commented Jun 24, 2020

When using a Stream, we can add an error via its .addError(error) function. Then any StreamBuilder that is listening to it could get the error object via the AsyncSnapshot object.
That allows us to return a different widget to the builder function when any error occurs.

Is there something similar that we can do with MomentumBuilder?

I know we can send an event and just show a SnackBar instead. But in some cases we want to show an error widget to the screen itself.

Any thoughts?

Thanks!

@xamantra
Copy link
Owner

@jezer07
I created this library in mind that I don't need to use FutureBuilder and StreamBuilder. I want to handle everything from the controller and let MomentumBuilder display my state.

The official docs covered this part in this section: Working with Streams - Error Handling

Here's the sample code from the docs:

class ChatController extends MomentumController<ChatModel> {

  // ...

  @override
  void bootstrap() {
    // ...
    model.roomsSubscription.onError((error, stackTrace) {
      print(error);
      print(stackTrace);
    });
    // ...
  } 

  // ...
}

I think if you call .addError(error), the callback .onError(...) will react to it. So basically inside this callback, you can do anything like setting an error property in the model and display the error using MomentumBuilder.

@xamantra
Copy link
Owner

xamantra commented Jul 1, 2020

Closing for inactivity...

@xamantra xamantra closed this as completed Jul 1, 2020
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

No branches or pull requests

2 participants