Too many devs cook all their logic inside the build() method โ then wonder why their app lags.
Every time Flutter rebuilds, your build() runs again. If youโre:
Doing API calls in there โ
Heavy calculations โ
Creating giant lists on the fly โ
โฆyouโre basically making your app redo the same expensive work over and over.
๐ง Example of a slow approach:
@override
Widget build(BuildContext context) {
final items = getItemsFromDatabase(); // โ BAD: runs every rebuild
return ListView(children: items.map((e) => Text(e)).toList());
}
โ Better: Do heavy work once in initState() or a state management class, then pass the data to your widget.
List<String> items = [];
@override
void initState() {
super.initState();
items = getItemsFromDatabase(); // โ Runs once
}
@override
Widget build(BuildContext context) {
return ListView(children: items.map((e) => Text(e)).toList());
}
๐ง Takeaway:
> โbuild() is for building UI, not doing the cooking.โ
If this tip saved your app from getting roasted, fuel the next spicy one here:
๐ buymeacoffee.com/ejjat โ
#flutterdev #performancetips #fluttertips #dailydev #buymeacoffee
