FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.75k stars 1.76k forks source link

010 - UserID not provided on first load #77

Closed FrankDomburg closed 4 years ago

FrankDomburg commented 4 years ago

Seems a lazy loading issue somewhere.

When I enter a userID, the home_view comes with a name in the header, but no posts. When I go back, enter the same userID, the posts become visible.

When I enter a userID, the home_view comes with a name in the header, but no posts. When I go back, enter the a different userID, the correct posts become visible.

So suspect that userID becomes available to late for the getPosts function to work. But don't understand why, given that the header is displayed correctly.

FrankDomburg commented 4 years ago

I solved this by making the StreamProvider in main.dart "lazy: false".

I am just not sure if this is the right approach.

FilledStacks commented 4 years ago

I think that is the right approach. I don't use the global streams in production. I mention in the video I'm only doing it to show that it's possible and what provider can do. But in production i don't use it.

azhar1038 commented 4 years ago

Hello @FilledStacks , I wanted to ask how should I implement themes(light and dark) without global streams?

When I was using redux, I was using a global StreamBuilder. Can you recommend a different way or give a hint how to implement it now?

FilledStacks commented 4 years ago

@mdazharuddin1011999 with a theme it's a bit different since it's consumed only within the UI part of the code. It's not actually used with business logic. I built a Theme Manager here that you can look at. It uses a global stream.

azhar1038 commented 4 years ago

Thanks for the link, Sir!