Flutter Other Performance Considerations
The purpose of this chapter is to be a ‘catch-all’ for anything else you should consider when building the most performant app possible.
Http Communication
Before we get into more Flutter performance topics, we should mention that most Flutter apps will be communicating with other computers. Such communication over a network is typically much slower than the highly-efficient Flutter user interface, so looking how your app communicates with other computers is a good place to start and can yield significant gains. What data are you getting from the server, do you really need all of it?Are you using a JSON format? If so, what about making the JSON field names smaller to save on data size.
Can you make any requests to the server parallel and have them
Use Constants When Possible
Avoid Rebuilding Widgets
When using stateless widgets, avoid possible instantiation/rebuilds by using the const keyword (for example the Texts in the example below)@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Rows")),
body: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Text("the quick brown wolf"),
const Text("the quick brown wolf"),
const Text("the quick brown wolf")
],
)
],
));
}
Using Constants Saves Memory
For any given const value, a single const object will be created and reused no matter how many times the const expression(s) are evaluated.getConst() => const [1, 2];
main() {
var a = getConst();
var b = getConst();
print(a === b); // true
}