Flutter is one of the fastest ways to build Android and iOS apps from a single codebase. It is also easy to pick up a few habits early that make your apps slower and your code harder to maintain. Here are five mistakes we see again and again while mentoring students, and how to fix each one.
1. Putting everything in one giant build() method
A 300-line build() method is hard to read and rebuilds more than it needs to. Break the UI into small widgets.
// Instead of one huge build method:
class ProfileScreen extends StatelessWidget {
const ProfileScreen({super.key});
@override
Widget build(BuildContext context) {
return const Column(
children: [
ProfileHeader(),
ProfileStats(),
ProfileActions(),
],
);
}
}
Smaller widgets are easier to test, reuse and understand.
2. Forgetting const
When a widget never changes, mark it const. Flutter can then skip rebuilding it entirely. Turn on the recommended lints (flutter_lints) and your editor will point out every place you missed it.
Tip
Run dart fix --apply on your project. It adds many missing const keywords and other small fixes automatically.
3. Calling setState for everything
setState is fine for small, local UI state like a toggle or a text field. But when the same data is needed across many screens, such as a logged-in user or a cart, passing it around with setState becomes messy. Learn one state management approach properly. Provider or Riverpod are great starting points.
4. Doing heavy work in the UI
Parsing a large JSON file or processing images on the main thread makes your app stutter. Move heavy work off the UI thread:
final result = await compute(parseLargeJson, rawJsonString);
Also make sure network calls happen in your logic layer, not inside build(), which can run many times per second.
5. Ignoring different screen sizes
An app that looks perfect on your phone may overflow on a small Android device or look stretched on a tablet. Use Expanded, Flexible, LayoutBuilder and MediaQuery instead of fixed pixel widths, and test on at least two screen sizes before release.
Key takeaways
- Split the UI into small widgets and use
constwherever you can. - Use
setStatefor local state, and Provider or Riverpod for shared state. - Keep heavy work off the UI thread and design for different screen sizes.
Want to learn Flutter the practical way? Techno Amaze Academy teaches Flutter and Dart through real projects, guided by developers who build production apps. Contact us to know about the next batch.