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

Error When rebuilding child in CustomRefresher #9

Closed
Flucadetena opened this issue Nov 7, 2020 · 4 comments
Closed

Error When rebuilding child in CustomRefresher #9

Flucadetena opened this issue Nov 7, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Flucadetena
Copy link

Flucadetena commented Nov 7, 2020

Hi, first of all, great package.

Im getting and error when I rebuild the child in CustomRefresher. I'm using a StaggeredGridView(or a ListView) inside the child, but I attach a controller to it as I need to listen to the scroll to know when it reaches the end and add more items to the list. To create an infinite scroll.

The problem is that when I add those items this error appears:

═══════ Exception caught by foundation library ════════════════════════════════
The following assertion was thrown while dispatching notifications for IndicatorController:
Build scheduled during frame.

While the widget tree was being built, laid out, and painted, a new frame was scheduled to rebuild the widget tree.

This might be because setState() was called from a layout or paint callback. If a change is needed to the widget tree, it should be applied as the tree is being built. Scheduling a change for the subsequent frame instead results in an interface that lags behind by one frame. If this was done to make your build dependent on a size measured at layout time, consider using a LayoutBuilder, CustomSingleChildLayout, or CustomMultiChildLayout. If, on the other hand, the one frame delay is the desired effect, for example because this is an animation, consider scheduling the frame in a post-frame callback using SchedulerBinding.addPostFrameCallback or using an AnimationController to trigger the animation.

When the exception was thrown, this was the stack
#0      WidgetsBinding._handleBuildScheduled.<anonymous closure>
package:flutter/…/widgets/binding.dart:783
#1      WidgetsBinding._handleBuildScheduled
package:flutter/…/widgets/binding.dart:806
#2      BuildOwner.scheduleBuildFor
package:flutter/…/widgets/framework.dart:2587
#3      Element.markNeedsBuild
package:flutter/…/widgets/framework.dart:4311
#4      State.setState
package:flutter/…/widgets/framework.dart:1264
...
The IndicatorController sending notification was: Instance of 'IndicatorController'
════════════════════════════════════════════════════════════════════════════════

The app doesn't break, but it would be nice to solve it.

Hope you can shine some light into it. Thanks! ;)

@gonuit
Copy link
Owner

gonuit commented Nov 16, 2020

Hi @Flucadetena 👋🏻!

Thanks! I'm doing my best! ❤️

Did you solve the problem? It looks like you were setting the state while building the widget, but maybe there is something I can improve inside the library? 🤔

@gonuit gonuit added the bug Something isn't working label Nov 16, 2020
@gonuit gonuit self-assigned this Nov 16, 2020
@Flucadetena
Copy link
Author

Hi!! I don't remember very well. But something like that I think. I was rebuilding the whole widget when I added a new set of items to the listView. At the end, I created a Provider so that when new items are added only the list is rebuild.

Think It was something like that ;)

Anyway a solved it so 🥇 ajajjajaja. Keep up with the packge, is great. And if you need help don't hesitate to ask :)

@do4Mother
Copy link

hi @gonuit, I got the same problem here. is it possible to rebuild the widget instead of a custom refresh indicator? because I want to handle if there is no data then the user can still refresh the data. but if i handle rebuild in listview builder. the text error cannot move to the center.

@gonuit
Copy link
Owner

gonuit commented Apr 23, 2021

Hi @do4Mother, I think that your question is not related to the library itself. You are receiving this error because this is how the Flutter framework works. If you want to rebuild the widget from the build method, you can use for example:

WidgetsBinding.instance.addPostFrameCallback((_) {
  setState(() {});
});

☝🏻 This will trigger the setState method right after the current frame/current build method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants