avatarDana Hartweg

Summary

A developer encountered an issue where code analysis failed after migrating Flutter code to a local package, despite the code being identical, and resolved it by deleting the ios/.symlinks directory.

Abstract

The author of the article was developing a generic Flutter widget using the flutter_bloc package for filtering and searching within a list of data. Intending to make the widget available to others, the author transferred the code into a local package. However, after linking the local package, the code failed to pass analysis, which was surprising as the code was unchanged. The developer explored various potential causes, such as analyzer version discrepancies, improper application of analysis options, and even the possibility of errors in the original code. After unsuccessful attempts at finding a solution through online searches, the developer stumbled upon a GitHub issue that suggested removing the ios/.symlinks directory, which resolved the analysis issues. The article also highlights the ease of linking a local package for development by using the path parameter in the pubspec.yaml file.

Opinions

  • The author was initially puzzled and frustrated by the unexpected failure of code analysis after migrating the code to a local package.
  • There was a consideration that the pedantic package might impose stricter rules on local packages, contributing to the analysis failure.
  • The author expresses surprise at the simplicity of linking a local package in Flutter.
  • There is a hint of humor and exasperation when the author suggests "Gremlins" as a potential cause of the analysis failure.
  • The author's tone suggests relief and satisfaction upon finding the solution to the problem in a somewhat unrelated GitHub issue.

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 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
Dart
Package Management
Flutter Package
Recommended from ReadMedium