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

@felangel felangel 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 added the enhancement New feature or request label Jun 13, 2019
@felangel felangel requested a review from jorgecoca June 13, 2019 01:27
@felangel felangel self-assigned this Jun 13, 2019
@felangel felangel added this to In progress in bloc Jun 13, 2019
Copy link
Collaborator

@jorgecoca jorgecoca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Good job!

@felangel
Copy link
Owner Author

LGTM! Good job!

Thanks! 🙏

@felangel felangel merged commit 1a8c2ab into master Jun 13, 2019
@felangel felangel deleted the feature/blocprovider-expose-dispose branch June 13, 2019 01:43
@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
Labels
enhancement New feature or request
Projects
bloc
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants