Home > Software engineering >  Flutter android APK have low frame rate
Flutter android APK have low frame rate

Time:08-08

I was working on flutter project and when i finished and build the APK and run it in my phone unfortunately i found that the framerate is low even that my phone is capable of running 120Hz.

I used the flutter tool in android studio to see what is the framerate and it was maximum 30Hz (When the app is idle), but when i start interacting with the app it goes up and down between 30Hz and 4Hz !!

I searched for an answer but i didn't get one.

If anyone have experience this issue before i will be grateful if he talk about the solution that helped him.

CodePudding user response:

Finally i solved the problem, i got an idea to put a print statement in the build section of every main widget to trace the problem. turns out that a screen widget was building itself along with its children and don't stop building.

The problem was specifically because of the body of this screen was a FutureBuilder Widget that return a Widget from Future function, turns out that the future builder keeps running and build the widget every time.

I solved the problem by assigning a variable to the FutureBuilder instead of a function.

late Future<Widget> dataFuture;

@override
void initState() {
  super.initState();

  // Assign the function value to the variable.
  dataFuture = retrieveData();
}

@override
Widget build(BuildContext context) {
  return FutureBuilder<Widget>(
    future: dataFuture , // Use the variable instead of the function.
    builder: (context, snapshot) {},
  );
}
  • Related