Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update setBusy to avoid unnecessary reconstruction #13

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

Closed
hanielbaez wants to merge 1 commit into FilledStacks:master from hanielbaez:master

Conversation

@hanielbaez
Copy link

@hanielbaez hanielbaez commented Jul 8, 2019

From my point of view call notifyListeners(), when setBusy(true) is a wasted, cause we rebuild all the consummer with no actually new data.

 void setBusy(bool value) {
 _busy = value;
 notifyListeners();
 notifyListeners() ;
}
Future getPosts(int userId) async {
 setBusy(true); //notifyListeners() been call for not reason
 posts = await _api.getPostsForUser(userId);
 setBusy(false); //there is when we need notifyListeners() 
 }

Copy link
Owner

I think you're missing the point. We need to rebuild the widget when we setBusy because we have to use the busy value to show a loading indicator when a widget with a model is busy. It's not called for no reason. When your widget doesn't have to show a busy indicator then you don't call setBuys. It should only be used if you want to show loading indication while performing asynchronous work.

Copy link
Author

Ok, correct me if I'm wrong; for example it would not be better to have a default busy true, so it is not necessary to call notifyListeners(), and we only call it when we received the post.

Copy link
Owner

FilledStacks commented Jul 9, 2019 via email

You can definitely do it that way but it won't work when you have refresh functionality. Say we want to reload that widgets data when we press a button. That means we call that same function again. We'll have to set it to busy to indicate it's busy. Then we perform our request and then we set it to idle again. So we end up with my implementation. I would not handle it that way because it also affects the Readability of the code. Which is also very important in the way I develop. It has to be explicit. Assuming every widget you build is always busy in construction in this app scenario won't work. It could probably work in some scenarios. Like one where widget with a model will ALWAYS fetch it's data using an async operation when constructed.
...
________________________________ From: Haniel Obed Baez <notifications@github.com> Sent: Monday, July 8, 2019 11:54:31 PM To: FilledStacks/flutter-tutorials Cc: Dane Mackier; Comment Subject: Re: [FilledStacks/flutter-tutorials] Update setBusy to avoid unnecessary reconstruction (#13) Ok, correct me if I'm wrong; for example it would not be better to have a default busy true, so it is not necessary to call notifyListeners(), and we only call it when we received the post. — You are receiving this because you commented. Reply to this email directly, view it on GitHub<#13?email_source=notifications&email_token=AA3M72WKG4RSIEUTZD5N7N3P6OZRPA5CNFSM4H66DAYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZOO3GI#issuecomment-509406617>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AA3M72SJWX37CEWRZV26YPDP6OZRPANCNFSM4H66DAYA>.
hanielbaez reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /