Context
I have been using package_a (ex: fluttertoast package) in my flutter project and it worked well. However, for some reasons, I have decided to change to a similar but better package.
Problem:
As soon as I change this package in my pubspec.yaml file, my IDE throws missing imports errors all over my codebase
- Wrong way
- Better Approach Create a separate class with a static method to display your toast
Call the static Method
In your app’s UI, invoke the static method to display your toast
What did we fix?
The alert_service has the class for showing the alert. Rather than changing the implementation in all of our app’s UI as in the former, in the later, we just need to change the package in the alert_service where it is used
Final Thoughts
Depending on other flutter packages is very important in flutter projects, however, it is important that even though we depend on these packages, we write modular and reusable code that is not too tightly coupled to dependencies.
Top comments (0)