Closed marcelomfranca closed 11 months ago
Thanks @marcelomfranca for this PR and detailed explanation!
Thanks @marcelomfranca for this PR and detailed explanation!
Thank you! Please do more tests to ensure everything is working. I'm waiting for a new version on pub.dev.
Replace GlobalScope with CoroutineScope
Description
This pull request aims to improve the code quality and resource management of the developer plugin package by replacing the usage of
GlobalScope
withCoroutineScope
in theFlutterContactsPlugin
class.GlobalScope
is a top-level coroutine scope that lives throughout the entire application lifecycle. While it may seem convenient for launching coroutines, it can lead to potential issues such as memory leaks and uncontrolled coroutine lifecycles. To address these concerns, we propose replacingGlobalScope
with a more controlledCoroutineScope
.Key Benefits
Controlled Coroutine Lifecycles: By using a
CoroutineScope
, we can ensure that coroutines are canceled when they are no longer needed, preventing memory leaks and improving resource management.Improved Code Readability: The use of
CoroutineScope
makes it clear where coroutines are launched and provides better code organization.Easier Debugging: Coroutines launched within a
CoroutineScope
can be tracked and monitored more effectively, simplifying debugging and maintenance.Alignment with Best Practices: Using
CoroutineScope
aligns our codebase with recommended best practices for managing coroutine lifecycles in Android applications.Overall, this change enhances the reliability and maintainability of the plugin, contributing to a more robust and efficient package for Flutter developers.
Testing Done
In addition, this pull request includes updates based on testing performed on Android One devices. The plugin was compiled into the project, and functionality was thoroughly tested to ensure that it operates as expected on this platform.