When flutter code analysis fails after migrating code to a local package
Or… how the heck is it even possible that the same exact code fails to pass analysis once it’s extracted into a local package?!
I’m working on a generic flutter widget using the
flutter_bloc package that makes it easier to filter and search a list of data (more on that coming soon, but it will expand on the initial work found here). I decided this could be beneficial to more folks than just myself, so I started up a local package with the intent of migrating my existing code wholesale, making sure it still worked properly, then continuing to expand the functionality.
Imagine my surprise after linking the local package and switching over to the new implementation when it started failing code analysis! The exact same code, only located (and imported) from a different directory.
I went down every rabbit hole imaginable:
- Is the analyzer version different somehow?
- Are analysis options not applying to packages for some reason?
pedantichave extra rules for packages?
- Did I botch something when transferring the code?
- Perhaps the code was actually broken before but code analysis was incorrect in the existing project?
- Gremlins? Definitely gremlins.
None of my usual Google search kung fu paid off; nothing came back as directly applicable to the issue at hand. I honestly don’t remember the keyword that finally led to success, but I landed here. Only indirectly related to the issue I was seeing, as no issues were being reported with the imports themselves, but lo and behold removing the
ios/.symlinks directory corrected the issue!
If you run into issues with a locally linked package and flutter code analysis, try removing the
ios/.symlinks directory before you do anything else.
Side note: I was pleasantly surprised at how easy it was to link a package for local development! Simply supply a
path parameter for the package in your
pubspec.yaml that points to the local directory containing the package and you’re all set.