Handling Upgrades
Handling Dependencies & SDK Upgrades
Upgrading dependencies in a large Flutter project like Talawa can sometimes be tricky due to "diamond dependency" conflicts. This is often caused by local packages (like talawa_lint) having stricter version constraints than the main project.
The Common Conflict: talawa_lint vs SDK
When you try to upgrade the Flutter SDK or main dependencies (like build_runner), you might encounter a version solving error related to analyzer or macros.
Why this happens:
- Newer SDKs/plugins require a newer version of the
analyzerpackage (e.g.,> 6.0). - Our local
talawa_lintpackage (located intalawa/talawa_lint) often has apubspec.yamlthat constrainsanalyzerto an older version (e.g.,< 6.0). - Only running
flutter pub upgradein the root folder does not update the constraints in the sub-package, causing the build to fail.
How to Fix It
If your upgrade is blocked by talawa_lint or similar local packages, follow this workflow:
-
Locate the Sub-Package: Go to the
talawa_lintdirectory:cd talawa_lint -
Update Constraints: Open
talawa_lint/pubspec.yamland broaden the version constraints for conflicting packages (usuallyanalyzerorcustom_lint).dependencies:
analyzer: ">=5.12.0 <7.0.0" # Example: Increase the upper bound -
Upgrade Sub-Package: Run upgrade inside the directory to generate a new lockfile for it:
flutter pub upgrade -
Handle Stubborn Conflicts (Dependency Overrides): Sometimes, a package (like
hive_generator) might still strictly require an olderanalyzerversion even after you fixtalawa_lint. In this case, you may need to force a newer version in the rootpubspec.yaml:dependency_overrides:
analyzer: ">=6.0.0 <8.0.0" # Force compatible range -
Upgrade Main Project: Return to the root directory and attempt the main upgrade again:
cd ..
flutter pub upgrade
Diagnosing Conflicts
To see exactly which package is causing a version lock, use the verbose flag:
flutter pub upgrade -v
Look for lines indicating that talawa depends on talawa_lint which in turn depends on a specific version of analyzer.