Home > Mobile >  How to add a Flutter plugin that does not support Null Safety
How to add a Flutter plugin that does not support Null Safety

Time:10-05

Hay, I want to make a "Privacy Policy Checkbox" that includes a Text Hyperlink, and I found Screenshot of the prerelease version of the artemis code generator package showing prereleases with the Null Safety badge

Option 2 - Check the repository

Sometimes the migration has been completed but not yet released on pub at all. There are a few ways of checking:

  • Look into the pubspec.yaml, the environment.sdk key should list '>=2.12.0 <3.0.0' (the lower bound may be higher; there are libraries that use '>=2.14.0 <3.0.0' but 2.12.0 is required for null safety).
  • Look into pull requests and search for null safety; maybe one is merged already which would indicate that the change is on the branch it was merged on
  • Look into issues and search for null safety; maybe one is closed and the maintainer dropped "Done" or something alike in the thread which would indicate that the change is on the branch it was merged on

If you find that indeed, the repository is on a version where it's null safe, you can use a git reference in your pubspec file:

  link:
    git:
      url: https://github.com/galonsos/link
      ref: master

Read more about referencing a package from git in the pub docs.

Option 3 - Check forks of the repository

This is something you will likely do together with option 2. When scrolling through issues and PRs, you might stumble over someone who says "I did this on my fork" or an open PR by someone who has converted the library over (this happened in your case: relevant PR). If you find an actively maintained fork that meets your requirements, reference that with a git reference in your pubspec file, just as before.

Option 4 - Open an issue and wait (if none exists yet)

This obviously depends on whether the author of the package is still active somewhere around or whether you have the time to wait. Either way, it's never a bad idea to open an issue for an issue.

Option 5 - Do it yourself

Migrating a library to null safety can be time consuming, depending on its size and complexity. Regardless, it may be your only option in case you have an extremely specific library you don't want to rewrite from the ground up and it's a good exercise to better understand the library and dart itself.

If you are nice, be the person you hoped you had found before you and open a PR to the original repository when you are done, so someone else is already helped with option 3 :) And, of course, use a git reference to use your newly upgraded package.

Option 6 - Use an alternative

This might not always work but could be faster than doing the null safety migration yourself. There are often other packages that do something similar in a slightly different way. And even if not, you can sometimes build a quick alternative yourself. A link can quickly be built using some GestureDetector or InkWell and the url_launcher package (which is the same setup used in the link package) for example.

  • Related