zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 619 forks source link

How to close a subscription? #714

Closed RobertoOrtis closed 4 years ago

RobertoOrtis commented 4 years ago

Hello,

I would like to know how to close a subscription or which would be the best way of avoiding opening a new subscription each time I enter a page in the app.

My issue: I have a subscription in my home page, and everytime I go to another page and then back to the home page, a new subscription is being made.

So, how can the close a subscription when leaving the home page, and how can I have a subscription that starts at the top of my app's hierarchy so doesn't matter how many times I leave or enter my home page, I keep the same subscription.

I am using version 4.0.0-alpha.3

micimize commented 4 years ago

@RobertoOrtis you're saying the Subscription widget isn't closing the subscription on dispose?

You could move the subscription code to the top in a provider or something for the other part

RobertoOrtis commented 4 years ago

@RobertoOrtis you're saying the Subscription widget isn't closing the subscription on dispose?

Yes. What would be the proper way to dispose it whenever I exit the page where the subscription is on?

You could move the subscription code to the top in a provider or something for the other part

I would like this way better but I am still learning flutter/dart... Could you please enlighten me and show me how it could be done?

RobertoOrtis commented 4 years ago

I managed to put the subscription on top of my tree by using BLoC pattern (flutter_bloc). Thank you!

JoshanTandukar commented 2 years ago

As for us we cant make subscription top level due to app complexity. Now this issue is same subscription double triples every time the tabs are changed and cannot find a way to dispose the previous connection even with subscription connection id (counter). We cant make subscription top level even if we want to using provider. Help needed.