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

Add extension on BuildContext #608

Closed
timrijckaert opened this issue Oct 24, 2019 · 7 comments
Closed

Add extension on BuildContext #608

timrijckaert opened this issue Oct 24, 2019 · 7 comments
Assignees
Labels
enhancement New feature or request pkg:flutter_bloc This issue is related to the flutter_bloc package release candidate Candidate for release pending successful build

Comments

@timrijckaert
Copy link

timrijckaert commented Oct 24, 2019

Similar to the proposal on the Provider package.
Are we down for some extension functions to easily get a Bloc and a Repository?

var fooBloc = context.bloc<FooBloc>();
var barRepo = context.repo<BarRepo>();
@timrijckaert timrijckaert changed the title extension functions on Context Add extension on BuildContext Oct 24, 2019
@felangel
Copy link
Owner

Hey @timrijckaert 👋
Thanks for opening an issue!

I think this is a great idea and there's a lot of potential to improve the of API via extensions. A couple of things I think we need to discuss first are:

  1. Doing this would require everyone to use Dart 2.6 which might not be feasible right now given that it's not available for the stable branch (yet).
  2. If provider supports this we would get it for free in flutter_bloc. (@rrousselGit)

Thoughts?

@felangel felangel self-assigned this Oct 24, 2019
@felangel felangel added discussion Open discussion for a specific topic enhancement candidate Candidate for enhancement but additional research is needed feedback wanted Looking for feedback from the community labels Oct 24, 2019
@tenhobi
Copy link
Collaborator

tenhobi commented Oct 24, 2019

This feature is for sure something we would love to use, but I would wait for Flutter first, how they use Extensions so we can align to the API etc. Also, because Flutter Bloc uses package:provider, we might, as you say, get those thing for free and it would be better to use their API as well, to make transition from/to provider better. 👍

@timrijckaert
Copy link
Author

I agree with all of the above. :)

@larssn
Copy link

larssn commented Oct 30, 2019

Extensions would remove quite a bit of boilerplate so I'm all for it. 👍

@felangel felangel added the dependency This issue has an external dependency label Dec 1, 2019
@felangel felangel added this to the v3.0.0 milestone Dec 18, 2019
@arnemolland
Copy link

This would be neat indeed. We're currently using a super simple extension:

extension BlocExtension on BuildContext {
  T bloc<T extends Bloc>() {
    return BlocProvider.of<T>(this);
  }
}

Though it may or may not be too simple

@larssn
Copy link

larssn commented Dec 18, 2019

@arnemolland It saves a bit of boilerplate, so it's probably fine. 🙂

@felangel
Copy link
Owner

Added the extensions in #816 and published in v3.2.0 of flutter_bloc 🎉

@felangel felangel added enhancement New feature or request pkg:flutter_bloc This issue is related to the flutter_bloc package release candidate Candidate for release pending successful build and removed dependency This issue has an external dependency discussion Open discussion for a specific topic enhancement candidate Candidate for enhancement but additional research is needed feedback wanted Looking for feedback from the community labels Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:flutter_bloc This issue is related to the flutter_bloc package release candidate Candidate for release pending successful build
Projects
None yet
Development

No branches or pull requests

5 participants