Your Build Method is Not a Kitchen

Your Build Method is Not a Kitchen

Aug 09, 2025

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

Gefällt dir dieser Beitrag?

Kaufe Izzat Rizal einen burger

Mehr von Izzat Rizal