Flutter is performant by default . Developers behind Flutter and Dart have spent an enormous amount of time to make their performance near-native . However, as we have recently developed & released the Rokomari app , Bangladesh’s largest online bookseller app using Flutter (Dart) – I have found several peak-points that require optimization .
Flutter, powered by Dart language, is an open-source SDK by Google to develop apps for Android, iOS, Linux, Windows, MacOS and the web from a single codebase .
Here, I share tips to optimize a Flutter app, from my experience, that scales:
- Avoid heavy-works on the main thread
- Employ isolates wherever necessary
- Mark static widgets as const
- Avoid rebuilding widgets
- Remove Container() if unnecessary
- Prefer SizedBox() or Nil() instead of blank Container()
- Use StatelessWidget if StatefulWidget is of no use
- Keep the Widget build() as simple as possible
- Avoid color gradients
- Add shrinkWrap:true to ListView.builder
- Apply RepaintBoundary() in animation works
- Cache both local and networked images
- Employ dispose() to release object memories
- Compress (encode and decode) data
- Make Color codes const
- Keep Flutter and Dart up-to-date
- Produce architecture-specific builds separately for phones, tablets and desktops
These tips will ensure a fast & lightweight high-performing Flutter app that runs on multiple platforms .