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

Expose dispose method on BlocProvider #347

Merged
merged 1 commit into from Jun 13, 2019

Conversation

@felangel
Copy link
Owner

commented Jun 13, 2019

Status

READY

Breaking Changes

YES

Description

  • Update BlocProvider to expose dispose method to allow full control over when a bloc should be disposed.

This PR allows us to go from:

class MyApp extends StatefulWidget {
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  MyBloc _myBloc;
  
  @override
  initState() {
    super.initState();
    _myBloc = MyBloc();
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      bloc: _myBloc,
      child: MyPage(),
    );
  }

  @override
  dispose() {
    _myBloc.dispose();
    super.dispose();
  }
}

To this:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      builder: (BuildContext context) => MyBloc(),
      dispose: (BuildContext context, MyBloc bloc) => bloc.dispose(),
      child: MyPage(),
    );
  }
}

Related PRs

List related PRs against other branches:

branch PR
BlocProvider to Automatically Dispose Blocs link

Todos

  • Tests
  • Documentation
  • Examples

Impact to Remaining Code Base

Breaking change to flutter_bloc API which will be included in flutter_bloc v0.16.0

@felangel felangel requested a review from jorgecoca Jun 13, 2019

@felangel felangel self-assigned this Jun 13, 2019

@felangel felangel added this to In progress in bloc Jun 13, 2019

@felangel felangel referenced this pull request Jun 13, 2019

Merged

Update BlocProvider to automatically dispose blocs #344

3 of 3 tasks complete
@jorgecoca
Copy link
Collaborator

left a comment

LGTM! Good job!

@felangel

This comment has been minimized.

Copy link
Owner Author

commented Jun 13, 2019

LGTM! Good job!

Thanks! 🙏

@felangel felangel merged commit 1a8c2ab into master Jun 13, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@felangel felangel deleted the feature/blocprovider-expose-dispose branch Jun 13, 2019

@felangel felangel moved this from In progress to Done in bloc Jun 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.