Tips to Optimize Performance Flutter

Tips to Optimize Performance Flutter



1. Avoid using stateful widget

Usually we rely on Stateful to use state in it. It's true that stateful is great but inside stateful has a heavy and bulky build function. Because Stateful has a special 'cache' mechanism which can be rebuilt if needed.

Stateful components must use the setState/useState functions in the function body. While the stateless component should not have this function due to its nature which does not have its own state.

You can use state in stateless by using State management like flutter_bloc, provider, get, etc.



2. Break down large widgets into multiple widgets

When you create a large and complex layout, splitting or splitting widgets into smaller ones. There are several ways of splitting widgets, one of them is Stateless/Stateful or methods.


3. Use pagination for long list 

Using pagination for data list management. Usually we call all the data in one call, this case makes the system slow and the application may exit. Sometimes when we have a very long list, and we want to make a drastic jump with scrolling. By creating pagination in a list or table view it is possible to retrieve some required data in one view.

For more details, please open the following link.



4. Use keyword const

Using the const key for constants that we can initialize at compile time. Use const as much as possible in widgets, as this allows you to reuse widgets and avoid unnecessary rebuilds caused by ancestors.



5. Avoid using Opacity

Avoid using the Opacity widget, this is because the Opacity widget directly causes rebuilding or rebuild every Frame. Usually we use it to hide a widget. Instead of using the Opacity widget you can replace using the Transform widget.




6. Use splash screen native


Using this flutter_native_splash package it automatically generates iOS, Android, and Web-native code to match the background color of these splash screens and native splash images. Supports dark mode, full screen, and platform specific options.



7. Reducing app size

Some other things you can do to make your app smaller are:

  • Remove unused resources
  • Minimize resource imported from libraries
  • Compress PNG and JPEG files


Conclusion

Flutter is fast to run apps without problems, but it's always good to follow good practices and optimize our apps as much as possible.

You can see the examples of the Flutter project I have made.

Check this out on Github


Tips to Optimize Performance Flutter
Nanang Prasetya 2 November, 2022
Share this post
Archive
Sign in to leave a comment
Tips to Secure Flutter App