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

RepositoryProvider.create and BlocProvider.create must work like didChangeDependencies #1936

Closed
PlugFox opened this issue Nov 15, 2020 · 7 comments
Assignees
Labels
pkg:flutter_bloc This issue is related to the flutter_bloc package question Further information is requested
Projects

Comments

@PlugFox
Copy link
Contributor

PlugFox commented Nov 15, 2020

RepositoryProvider.create and BlocProvider.create must work like didChangeDependencies, not initState.
They must depend on their dependencies like InheritedWidget.
This is flutter way and reactive data binding.

image
image

I use this crutch with bloc library for blocs lifecycle and dependency management:
https://gist.github.com/PlugFox/80fe552257546f0b50c7f625324da5bf

@felangel felangel self-assigned this Nov 16, 2020
@felangel felangel added investigating Investigating the issue pkg:flutter_bloc This issue is related to the flutter_bloc package question Further information is requested labels Nov 16, 2020
@felangel felangel added this to To do in bloc via automation Nov 16, 2020
@PlugFox
Copy link
Contributor Author

PlugFox commented Nov 17, 2020

I am currently solving this problem with a widget like this.
https://gist.github.com/PlugFox/80fe552257546f0b50c7f625324da5bf
But I would like it to be supported by the BlocProvider

@rrousselGit
Copy link

rrousselGit commented Nov 25, 2020

As appealing as it may sound, there are numerous limitations around InheritedWidgets that makes this approach dangerous.

This includes:

We can debate whether these scenarios are worse considering. For now, provider takes the easy path and prevents it to avoid potential surprising behaviors.

That's another of the reasons why I made Riverpod. It is able to safely implement such pattern. With Riverpod, those edge-cases do not exist.

@felangel
Copy link
Owner

felangel commented Mar 2, 2021

@PlugFox can you take a look at PlugFox/bloc_didchangedependencies#1? I believe I was able to achieve the desired behavior. Let me know what you think 👍

@felangel felangel added waiting for response Waiting for follow up and removed investigating Investigating the issue labels Mar 2, 2021
@PlugFox
Copy link
Contributor Author

PlugFox commented Mar 2, 2021

@felangel PlugFox/bloc_didchangedependencies#1

This is not a solution of the problem)
Do not think about "User" as user.
Think it about model and repository dependency may changed over time.

Need to use watch, not read.

This may changed overtime from ui (lifting state) or from data layer.
I often see similar problems with other people.

@felangel felangel added this to the v7.0.0 milestone Mar 5, 2021
@PlugFox
Copy link
Contributor Author

PlugFox commented Mar 9, 2021

@felangel If you need any help, feel free to contact me.
I will try to help and explain everything I can.

I don’t have much time and I don’t want to do a pull request without agreeing on plans, as this may go against your views.

Thank you for admitting the problem)

@felangel felangel removed the waiting for response Waiting for follow up label Mar 18, 2021
@felangel felangel modified the milestones: v7.0.0, v7.1.0 Mar 18, 2021
@felangel
Copy link
Owner

Marking this as won't fix because this behavior is implemented by provider and is intentional as Remi pointed out in #1936 (comment).

bloc automation moved this from To do to Done Oct 25, 2021
@felangel felangel removed this from the v7.x.x milestone Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:flutter_bloc This issue is related to the flutter_bloc package question Further information is requested
Projects
bloc
  
Done
Development

No branches or pull requests

3 participants