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

Passing the context onReorder callback #5

Closed
dxps opened this issue Apr 1, 2019 · 1 comment
Closed

Passing the context onReorder callback #5

dxps opened this issue Apr 1, 2019 · 1 comment

Comments

@dxps
Copy link

dxps commented Apr 1, 2019

Hi Matej,

I want to use a BLoC (concretely, I am using the flutter_bloc package) inside the onReorder callback in order to 'announce' the changes and persist them.

But I would need to have access to the BuildContext to get the BLoC using something such as BlocProvider.of<MyCustomBloc>(context). So, in a StatelessWidget, a concrete implemenetation of onReorder callback should have this context as parameter as well:

  _onReorder(Key itemKey, Key newPositionKey, BuildContext context) {
    // ...
 }

Of course, for the moment, a StatefulWidget can be used to just store the BLoC retrieved from hierarchy in its state.

What do you think?

Thanks!

@dxps
Copy link
Author

dxps commented Apr 1, 2019

Sorry, my bad, silly question ... 😄
Solution is to just declare the 'extended' function like this:

myBloc = BlocProvider.of<MyCustomBloc>(context);
return ReorderableList(
  onReorder: (itemKey, newPositionKey) => _onReorder(itemKey, newPositionKey, myBloc),
  ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant