When flutter code analysis fails after migrating code to a local package

Dana Hartweg
Mar 12 · 2 min read

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?!

Seriously?
Seriously?

I’m working on a generic flutter widget using theflutter_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?
  • Does pedantic have 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!

TL;DR

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.

Flutter Community

Articles and Stories from the Flutter Community

Dana Hartweg

Written by

Senior Front End Software Engineer, InVision Studio

Flutter Community

Articles and Stories from the Flutter Community

More From Medium

More from Flutter Community

More from Flutter Community

More from Flutter Community

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade