Deferred Keyword In Flutter

Muhammad Bilal Rehman Khan
1 min readMay 14, 2023

Flutter Development Hack: Leveraging Deferred Keyword for Efficient Code Loading and Improved Performance! 📈💪

WHAT IS DEFERRED KEYWORD??

The deferred keyword in Flutter is a powerful tool that enables lazy loading of code, allowing developers to delay the loading of certain parts of their application until they are actually needed. This can be especially beneficial for large applications with complex features, as it helps optimize app performance by reducing the initial load time and memory consumption.

IMPLEMENTATION

Import the deferred library

import 'package:project_name/ml_model.dart' deferred as ml;

Implement the lazy loading

void loadMLModels() async {
await ml.loadLibrary();
// Code for loading machine learning models from the ml package
ml.loadModels();
}

onPressed: () {
loadMLModels();
// Use the loaded machine learning models for predictions
ml.predict(imageData);
}

Thank you for taking the time to explore the power of the deferred keyword in Flutter. If you found this article helpful, feel free to follow me on LinkedIn for more insightful content. Also, don’t forget to check out my GitHub profile for more exciting projects and code samples. Happy coding!

LinkedIn: https://www.linkedin.com/in/bilalrehman08/

Github : https://github.com/BilalRehman08

--

--

Muhammad Bilal Rehman Khan

Senior Flutter Developer | Flutter Trainer | Software Engineer | Mobile App Developer