Skip to content

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
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
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants