close

[Solved] Generator cannot target libraries that have not been migrated to null-safety

Hello Guys How are you all? Hope You all a re fine. When I try to upgrade my flutter app to flutter 2.0. I am Facing an Error. Flutter 2.0 upgrade, pub get failed with nonsense dependency behavior like Generator cannot target libraries that have not been migrated to null-safety. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Generator cannot target libraries that have not been migrated to null-safety Occurs ?

When I am trying flutter pub run build_runner build –delete-conflicting-outputs this command I am faced below error in my terminal.

My flutter and dart version already updated, Here is my terminal log.

Here is my pubspec.yaml file

How to solve this Error ?

Question: How to solve Generator cannot target libraries that have not been migrated to null-safety ?
Answer : After flutter upgraded Null Safety most of users having this issue with plugins. Actually I found out that json_serializable >=4.0.0 depends on json_annotation >=4.0.0 <4.1.0 and the json_annotation: ^4.0.0 includes Null Safety but json_serializable: ^4.0.2 does not, so the error is occurring.

Solution 1

After flutter upgraded Null Safety most of users having this issue with plugins. Actually I found out that json_serializable >=4.0.0 depends on json_annotation >=4.0.0 <4.1.0 and the json_annotation: ^4.0.0 includes Null Safety but json_serializable: ^4.0.2 does not, so the error is occurring.

So Just You have to downgrade your package version

and

Solution 2

The problem is this all depends on if you are intending on upgrading your overall project to enable null safety or not. If you want to use the latest json_serializable packages (that have enabled null safety), you will need up specify it as such in your environment. So that you have to enable In your pubspec.yaml, if you enable null safety with the following:

Summery

So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below on your suggestion.

Check Out Below Article

Milan Dhameliya is an Information Technology Engineer. By profession, he is a Full Stack developer with knowledge of multiple back-end platforms (e.g., PHP, Node.js, Python) and frontend Flutter frameworks.

Leave a Comment