0

I might be misunderstanding the usage of this tool but I see the following

enter image description here

which is not good because it goes over 16ms. That piece of red bars happens always the first time that I load a page (widget) that has a FutureBuilder:

@override
  Widget build(BuildContext context) {
    // Page template is a StatelessWidget that wraps a Scaffold with common widgets, nothing special
    return PageTemplate(
      child: FutureBuilder(
        future: getList(), // <-- this takes about 1 second
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            List<Operator> list = snapshot.data;
            return ListView.builder(
              itemCount: list.length,
              itemBuilder: (context, index) {
                return MyWidget();
              },
            );
          }

          return Center(
            child: CircularProgressIndicator(),
          );
        },
      ),
    );

The app is in Run mode: profile. Sometimes the page with the FutureBuilder might generate even more red bars so I am wondering:

  • is this fine because I am just misunderstanding the tool? The overlays above the app tell me that on averages I am at GPU 10ms/frame and UI 6 ms/frame so it should be fine. But I can't get why sometimes I get this in the future (taken from android studio; dotted white line is 16fps limit):

enter image description here

I suspect the above "issue" (if we can call it issue) might happen because I am not properly using the FutureBuilder. I read this (I try to put const everywhere and I split widgets as much as I can to optimize when rebuild happens) and I think that futurebuilder rebuilds a lot so this might be the problem. But it has to rebuild to check if the future has finished! So?

thanks

Raffaele Rossi
  • 2,997
  • 4
  • 31
  • 62
  • You may want to read https://stackoverflow.com/questions/52249578/how-to-deal-with-unwanted-widget-build – Rémi Rousselet Dec 05 '19 at 15:52
  • @RémiRousselet in fact the FutureBuilder gives me red bars! Other parts of the app doesn't (or rarely, but that's because some flutter widget have automatic animations). So your suggestion is to use stateful widgets with FutureBuilder? – Raffaele Rossi Dec 05 '19 at 15:56

0 Answers0