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

Can closing the Bloc become optional? #740

Closed
RaviKavaiya opened this issue Dec 24, 2019 · 1 comment
Closed

Can closing the Bloc become optional? #740

RaviKavaiya opened this issue Dec 24, 2019 · 1 comment
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@RaviKavaiya
Copy link

First of all, this is not an issue. Need some help.

Hello, I am using this package after a long, updated from v0.15.0 (flutter_bloc).
I have an older application that was using 0.15.0, I updated dependency to 2.0.0 (bloc) and 2.1.1 (flutter_bloc).

Now, I get warnings of closing the sinks (the bloc objects) (instances of dart.core.Sink). I know, this is USEFUL.

BUT, imagine below situation :

void main() {
  BlocSupervisor.delegate = AppBlocDelegate();

  MyBloc bloc1 = MyBloc();

  bloc1.listen((state) {
    if (state is ProcessDone) {
      // do some processing, and then...
      // runApp(MyApp());
    }
  });
  bloc1.add(StartProcess());
}

Now, I get warning here, too. I can't close this bloc in void main() !!!

Moreover, I don't want to move this initialization logic into a widget. (To be honest, I have the code to initialize SharedPreferences in 'MyBloc1', so that preferences load before I show anything to user.)

Any suggestions?

@felangel
Copy link
Owner

Hi @RaviKavaiya 👋
Thanks for opening an issue!

This is a duplicate of #587 and there is an issue open on the Dart Linter to resolve false positives at dart-lang/sdk#57882.

Regarding your specific question, I would either avoid creating streams and subscriptions directly in main because they will never be closed or you can simply disable the lint rule as is done within Flutter itself.

Hope that helps!

@felangel felangel self-assigned this Dec 24, 2019
@felangel felangel added the duplicate This issue or pull request already exists label Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants