Skip to content

Use streams instead of callbacks to get the playback state, etc. #20

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

Merged
merged 1 commit into from
Jan 4, 2019
Merged

Use streams instead of callbacks to get the playback state, etc. #20

merged 1 commit into from
Jan 4, 2019

Conversation

hacker1024
Copy link
Contributor

Fixes #18 .

@ryanheise ryanheise merged commit dbabf77 into ryanheise:master Jan 4, 2019
@ryanheise
Copy link
Owner

Looks good! I've merged it and will add further changes: encapsulate all state changes, slight naming changes, cancel the stream subscription when disconnecting in the example.

@hacker1024
Copy link
Contributor Author

cancel the stream subscription when disconnecting in the example

I just made this mistake; be sure to also cancel it in the dispose() method of your stateful widget.

@hacker1024
Copy link
Contributor Author

It might be good to put this comment from the Flutter docs in your README.

If a State's build method depends on an object that can itself change
state, for example a ChangeNotifier or Stream, or some other object to
which one can subscribe to receive notifications, then the State should
subscribe to that object during initState, unsubscribe from the old
object and subscribe to the new object when it changes in
didUpdateWidget, and then unsubscribe from the object in dispose.

@hacker1024 hacker1024 deleted the patch-1 branch January 4, 2019 04:22
@ryanheise
Copy link
Owner

Interestingly the dispose() method is not called in the example, but I've added in a call to disconnect in there anyway, just because it did look a bit suspicious having a connect in initState and no disconnect in dispose.

With didUpdateWidget, the way I see it is that it's probably not practical for every plugin that provides streams to repeat the usual warnings about remembering to subscribe and cancel correctly and that anyone intending to use streams should read the streams documentation first. But if it proves to be enough of a stumbling block down the track, I may revisit this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use streams instead of callbacks for playback state and queue changes
2 participants