Flutter json_serializable 5.0.0 is not working along with auto_route
Solution 1
try this code
json_serializable: any
I hope this will work.
Solution 2
this step work with me
1 - add dependencies in pubspec.yaml file
dio: ^4.0.0
json_serializable: ^4.1.4
json_annotation: ^4.0.1
2- run this command to reset version
dart pub upgrade --null-safety
Solution 3
This is happening because the auto_route_generator
depends on json_serializable: ^4.1.4
internally inside that package, but you are using json_serializable
externally and the version used in both cases doesn't match, thus the error,
One solution for this is you can use both versions and mention one version inside dependencies:
and another inside dependency_overrides:
like this:
dependencies:
...
json_serializable: ^5.0.0
...
dependency_overrides:
...
json_annotation: ^4.0.1
json_serializable: ^4.1.4
...
And the problem should be solved. If any further complication arises you can always check which version is used inside the package's internal pubspec.yaml
and add them as dependency_overrides:
in your code.
Admin
Updated on December 31, 2022Comments
-
Admin over 1 year
I'm getting below error after upgrading the json_serializable lib from 4.1.4 to 5.0.0
can anyone please explain what is wrong with the versions I'm using?
Because no versions of auto_route_generator match >2.1.0 <3.0.0 and auto_route_generator 2.1.0 depends on analyzer >=0.40.0 <2.0.0, auto_route_generator ^2.1.0 requires analyzer >=0.40.0 <2.0.0. And because json_serializable >=5.0.0 depends on analyzer ^2.0.0, auto_route_generator ^2.1.0 is incompatible with json_serializable >=5.0.0. So, because carer_connect depends on both json_serializable ^5.0.0 and auto_route_generator ^2.1.0, version solving failed. pub get failed (1; So, because carer_connect depends on both json_serializable ^5.0.0 and auto_route_generator ^2.1.0, version solving failed.)
This is my
pubspec.yaml
filename: demo description: demo publish_to: 'none' version: 1.0.0+1 environment: sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter cupertino_icons: ^1.0.2 dio: ^4.0.0 auto_route: ^2.2.0 json_serializable: ^5.0.0 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^1.0.0 build_runner: auto_route_generator: ^2.1.0 flutter: uses-material-design: true generate: true assets: - assets/icons/ - assets/config/