Removing a Flutter Package: Step-by-Step Guide
You might wonder why this blog post is necessary when removing Flutter packages seems like one of the first things a developer learns. However, as you delve deeper into the intricate world of Flutter, you’ll uncover hidden nuances. How hard you try to fix the version it doesn’t help.
Despite your best efforts, your application continues to access the outdated version you believed was removed simply by deleting the package declaration from pubspec.yaml
and running flutter pub get
again. Even version locking doesn’t work.
First, let’s understand the circumstances under which you would need to perform this action:
- After updating the package version, you discovered that the new package has caused issues and disrupted previous functionalities. As a result, you now desire to revert back to the previous version.
- Your application was working fine in the morning but now it’s showing some error and you don’t know why it happened.
Let’s see how you can solve this problem:
- First, remove the package with
flutter pub remove {package_to_be_removed}
- Now navigate to
.pub-cache/hosted
directory. Generally, this directory is present at the user-level directories. - There are two folders present at this path
pub.dartlang.org
andpub.dev
- Navigate to both directories and remove the package folder, using
rm command
- Now in the terminal run
flutter pub add {package_to_be_added}:{package_version_to_be_added}
This should resolve the package dependency issues.
Go ahead and give it a whirl!
If it works it works otherwise it’s time to do what every self-respecting developer does: embark on an epic quest to consult the sacred texts of Google!