I got an error while trying to use built value generator
This was the error that i got.
[INFO] Running build...
[INFO] Generating SDK summary.
[SEVERE] built value generator:built value on lib/json_parsing.dart:
Bad state: Unexpected diagnostics:
C:\src\flutter\bin\cacheldart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] built_value_generator:built_value on lib/json_parsing.dart:
Bad state: Unexpected diagnostics:
C:\src\Flutter\bin\cache\dart-sdk\lib\core uri.dart:3259:39 - Expected an identifier.
[SEVERE] built_value_generator:built_value on lib/json_parsing.dart:
Bad state: Unexpected diagnostics:
C:\src\flutter\bin\cache\dart-sdk\lib\coreluri.dart:3259:39 - Expected an identifier.
the class which i was using running the built value generator on
import 'package:built_value/built_value.dart';
part 'src/json_parsing.g.dart';
abstract class Article implements Built<Article, ArticleBuilder> {
Article._();
factory Article([void Function(ArticleBuilder) updates]) = _$Article;
}
As mentioned by #Mohammad on the comments, and from this issue, just add this to pubspec.yaml:
dependency_overrides:
analyzer: '0.39.14'
Note, this is a sibling of dependencies and dev_dependencies.
It looks like build_runner version 1.10.1 pinned the version of analyzer to 0.39.14.
Try to update build_runner: build_runner: ^1.10.1 without adding dependency_overrides: and see.
Related
I am trying to generate dart types from my schema.graphql file described in ferry doc.
https://ferrygraphql.com/docs/codegen
I get this error while building the graphql code
flutter pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 543ms
[INFO] Precompiling build script......
[INFO] Precompiling build script... completed, took 7.6s
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 890ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Running build...
[INFO] Generating SDK summary...
[INFO] 4.5s elapsed, 4/5 actions completed.
[INFO] Generating SDK summary completed, took 3.5s
[WARNING] gql_build:serializer_builder on lib/$lib$:
Your current `analyzer` version may not fully support your current SDK version.
Analyzer language version: 2.14.0
SDK language version: 2.16.0
Please update to the latest `analyzer` version (3.3.1) by running
`flutter packages upgrade`.
If you are not getting the latest version by running the above command, you
can try adding a constraint like the following to your pubspec to start
diagnosing why you can't get the latest version:
dev_dependencies:
analyzer: ^3.3.1
[INFO] 6.0s elapsed, 4/5 actions completed.
[INFO] 7.1s elapsed, 5/9 actions completed.
[INFO] 8.1s elapsed, 5/9 actions completed.
[INFO] 9.3s elapsed, 5/9 actions completed.
[INFO] 16.4s elapsed, 5/9 actions completed.
[INFO] 18.3s elapsed, 5/9 actions completed.
[SEVERE] built_value_generator:built_value on lib/schema.schema.gql.dart:
Error in BuiltValueGenerator for /ferry_codegen_test/lib/schema.schema.gql.dart.
Please make the following changes to use built_value serialization:
1. Declare GENUM_AQUATIC_ACTIVETYPE.serializer as: static Serializer<GENUM_AQUATIC_ACTIVETYPE> get serializer => _$gENUMAQUATICACTIVETYPESerializer; got static Serializer<GENUM_AQUATIC_ACTIVETYPE> get serializer => _$genumAquaticActivetypeSerializer;
2. Declare GENUM_AQUATIC_BREEDINGLEVEL.serializer as: static Serializer<GENUM_AQUATIC_BREEDINGLEVEL> get serializer => _$gENUMAQUATICBREEDINGLEVELSerializer; got static Serializer<GENUM_AQUATIC_BREEDINGLEVEL> get serializer => _$genumAquaticBreedinglevelSerializer;
3. Declare GENUM_AQUATIC_CARELEVEL.serializer as: static Serializer<GENUM_AQUATIC_CARELEVEL> get serializer => _$gENUMAQUATICCARELEVELSerializer; got static Serializer<GENUM_AQUATIC_CARELEVEL> get serializer => _$genumAquaticCarelevelSerializer;
4. Declare GENUM_AQUATIC_DIET.serializer as: static Serializer<GENUM_AQUATIC_DIET> get serializer => _$gENUMAQUATICDIETSerializer; got static Serializer<GENUM_AQUATIC_DIET> get serializer => _$genumAquaticDietSerializer;
5. Declare GENUM_AQUATIC_SCHOOLING.serializer as: static Serializer<GENUM_AQUATIC_SCHOOLING> get serializer => _$gENUMAQUATICSCHOOLINGSerializer; got static Serializer<GENUM_AQUATIC_SCHOOLING> get serializer => _$genumAquaticSchoolingSerializer;
6. Declare GENUM_AQUATIC_SWIMLEVEL.serializer as: static Serializer<GENUM_AQUATIC_SWIMLEVEL> get serializer => _$gENUMAQUATICSWIMLEVELSerializer; got static Serializer<GENUM_AQUATIC_SWIMLEVEL> get serializer => _$genumAquaticSwimlevelSerializer;
7. Declare GENUM_AQUATIC_TEMPERAMENT.serializer as: static Serializer<GENUM_AQUATIC_TEMPERAMENT> get serializer => _$gENUMAQUATICTEMPERAMENTSerializer; got static Serializer<GENUM_AQUATIC_TEMPERAMENT> get serializer => _$genumAquaticTemperamentSerializer;
8. Declare GENUM_AQUATIC_TEMPUNIT.serializer as: static Serializer<GENUM_AQUATIC_TEMPUNIT> get serializer => _$gENUMAQUATICTEMPUNITSerializer; got static Serializer<GENUM_AQUATIC_TEMPUNIT> get serializer => _$genumAquaticTempunitSerializer;
9. Declare GENUM_AQUATIC_TYPE.serializer as: static Serializer<GENUM_AQUATIC_TYPE> get serializer => _$gENUMAQUATICTYPESerializer; got static Serializer<GENUM_AQUATIC_TYPE> get serializer => _$genumAquaticTypeSerializer;
10. Declare GENUM_BIT_TYPE.serializer as: static Serializer<GENUM_BIT_TYPE> get serializer => _$gENUMBITTYPESerializer; got static Serializer<GENUM_BIT_TYPE> get serializer => _$genumBitTypeSerializer;
11. Declare GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE.serializer as: static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE> get serializer => _$gENUMCOMPONENTMEDIAMEDIAUPLOADMEDIATYPESerializer; got static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_MEDIATYPE> get serializer => _$genumComponentmediamediauploadMediatypeSerializer;
12. Declare GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS.serializer as: static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS> get serializer => _$gENUMCOMPONENTMEDIAMEDIAUPLOADSTATUSSerializer; got static Serializer<GENUM_COMPONENTMEDIAMEDIAUPLOAD_STATUS> get serializer => _$genumComponentmediamediauploadStatusSerializer;
13. Declare GENUM_CONTRIBUTE_TYPE.serializer as: static Serializer<GENUM_CONTRIBUTE_TYPE> get serializer => _$gENUMCONTRIBUTETYPESerializer; got static Serializer<GENUM_CONTRIBUTE_TYPE> get serializer => _$genumContributeTypeSerializer;
14. Declare GENUM_FUNFACT_CATEGORY.serializer as: static Serializer<GENUM_FUNFACT_CATEGORY> get serializer => _$gENUMFUNFACTCATEGORYSerializer; got static Serializer<GENUM_FUNFACT_CATEGORY> get serializer => _$genumFunfactCategorySerializer;
15. Declare GENUM_FUNFACT_STATUS.serializer as: static Serializer<GENUM_FUNFACT_STATUS> get serializer => _$gENUMFUNFACTSTATUSSerializer; got static Serializer<GENUM_FUNFACT_STATUS> get serializer => _$genumFunfactStatusSerializer;
16. Declare GENUM_PRODUCT_CATEGORY.serializer as: static Serializer<GENUM_PRODUCT_CATEGORY> get serializer => _$gENUMPRODUCTCATEGORYSerializer; got static Serializer<GENUM_PRODUCT_CATEGORY> get serializer => _$genumProductCategorySerializer;
17. Declare GENUM_PRODUCT_STATUS.serializer as: static Serializer<GENUM_PRODUCT_STATUS> get serializer => _$gENUMPRODUCTSTATUSSerializer; got static Serializer<GENUM_PRODUCT_STATUS> get serializer => _$genumProductStatusSerializer;
[INFO] 21.9s elapsed, 5/9 actions completed.
[WARNING] No actions completed for 15.9s, waiting on:
- built_value_generator:built_value on lib/main.dart
- built_value_generator:built_value on test/widget_test.dart
- built_value_generator:built_value on lib/schema.schema.gql.dart
- built_value_generator:built_value on lib/serializers.gql.dart
[INFO] 22.9s elapsed, 9/10 actions completed.
[INFO] Running build completed, took 23.0s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 33ms
[SEVERE] Failed after 23.0s
pub finished with exit code 1
I think ferry generator having issues with graphql ENUM types
Can anyone help me to resolve the issue?
Thanks
reproduce repo https://github.com/aquadesk/ferry_codegen_test
pubspec.yaml
name: ferry_codegen_test
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.16.1 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
ferry: ^0.10.4
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
ferry_generator: ^0.4.4
build_runner: ^2.1.7
flutter:
uses-material-design: true
I think the schema.graphql file is too big to post here.
so I will put a part of it that seems to be an issue.
enum ENUM_AQUATIC_TEMPUNIT {
F
C
}
enum ENUM_AQUATIC_TYPE {
fish
frog
}
enum ENUM_BIT_TYPE {
youtube
instagram
blog
site
commerce
facebook
}
I found the fix here
https://github.com/gql-dart/gql/pull/225
Pull down this repo gql in your local and checkout the commit
14e8d3602ebb93f14a2285247c80a9b70b1eb71b which is this change
https://github.com/gql-dart/gql/commit/14e8d3602ebb93f14a2285247c80a9b70b1eb71b
and put this at the end of your pubspec.yaml
dependency_overrides:
gql_code_builder:
path: ../../../gql/codegen/gql_code_builder
when running flutter pub run build_runner build I get this error.
Failed to build build_runner:build_runner:
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:258:50: Error: The property 'displayString' is defined in multiple extensions for 'TargetKind' and neither is more specific.
- 'TargetKind' is from 'package:meta/meta_meta.dart' ('../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart').
Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
var kindNames = kinds.map((kind) => kind.displayString).toList()
^^^^^^^^^^^^^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:1950:14: Context: This is one of the extension members.
String get displayString {
^^^^^^^^^^^^^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart:91:14: Context: This is one of the extension members.
String get displayString {
^^^^^^^^^^^^^
../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:260:36: Error: The getter 'commaSeparatedWithOr' isn't defined for the class 'List<dynamic>'.
- 'List' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'commaSeparatedWithOr'.
var validKinds = kindNames.commaSeparatedWithOr;
This issue is related to outdated dependencies most likely, I had a similar one just today.
Run flutter pub upgrade and it should work!
Those who are experiencing this problem, just overwrite the "meta" dependency.
just add these lines to pubspec.yaml
dependency_overrides:
meta: 1.6.0
This might solve your issue, and there is well discussed github discussion https://github.com/dart-lang/sdk/issues/46687
I have a dart project with unit tests. When I run the unit tests locally they run successfully.
I added CI to the project with Github Actions. The same unit tests that run successfully locally, fail on Github Actions with the following error:
00:00 +0: loading test/foo_test.dart
00:01 +0: loading test/foo_test.dart
00:01 +0 -1: loading test/foo_test.dart [E]
Failed to load "test/foo_test.dart":
Couldn't resolve the package 'foo' in 'package:foo/foo.dart'.
test/foo_test.dart:5:8: Error: Not found: 'package:foo/foo.dart'
import 'package:foo/foo.dart';
^
test/foo_test.dart:33:26: Error: Method not found: 'Bar'.
final bar = Bar(
^^^^^^^^^^^^
00:01 +0 -1: Some tests failed.
Error: Process completed with exit code 1.
foo_test.dart imports foo.dart as a package (not relative path).
import 'package:foo/foo.dart'
The issue was caused due to me renaming the package name in pubspec.yaml.
pubspec.yaml:
name: foo_bar # <---- this was renamed from 'foo' to 'foo_bar'
description: An example dart project
version: 1.0.0
...
Any changes to pubspec.yaml requires running flutter pub get for the changes to take effect - including changing the package name, version, etc.
I created a new project, added dependencies
when I launch it
flutter pub run build_runner build
I get:
/C:/Users/Michael/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:1600:40: Error: Getter not found: 'topLevelVariable'.
return kinds.contains(TargetKind.topLevelVariable);
^^^^^^^^^^^^^^^^
/C:/Users/Michael/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Getter not found: 'topLevelVariable'.
case TargetKind.topLevelVariable:
^^^^^^^^^^^^^^^^
/C:/Users/Michael/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Type 'dynamic' of the case expression is not a subtype of type 'TargetKind' of this switch
expression.
- 'TargetKind' is from 'package:meta/meta_meta.dart' ('/C:/Users/Michael/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/meta-1.3.0/lib/meta_meta.dart').
case TargetKind.topLevelVariable:
^
/C:/Users/Michael/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2001:13: Context: The switch expression is here.
switch (this) {
^
pub finished with exit code 1
I've read everything on stackoverflow, but I haven't found a solution.
Any idea?
Specify the analyzer version
analyzer: 1.5.0
Warning: do not up to the latest version, because it depends on meta package as is flutter_test - where you can't specify the version
I have 2 issues that only appear when executing flutter build web.
Sometimes flutter build web fails complaining (wrongly) about types that were not compatible (see below).
Sometimes the build process finishes but then the web app doesn't work: doesn't display anything and there are no messages in the console.
The error I mention is something like this:
% flutter build web
Target dart2js failed: Exception: lib/main.dart:24:31:
Error: A value of type 'ApiUsersRepository' can't be assigned to a variable of type 'UsersRepository'.
- 'ApiUsersRepository' is from 'package:my_app/api_users_repo.dart' ('lib/api_users_repo.dart').
- 'UsersRepository' is from 'lib/users_repo.dart'.
final UsersRepository usersRepository = ApiUsersRepository();
^
Error: Compilation failed.
The app is working in iOS and web when developing.
The solution
I changed all imports of my files like:
import 'package:my_app/users_repo.dart';
To:
import 'users_repo.dart';
More Details
Investigating the error about types, I found this issue, where the important part is this comment: after changing every import to relative format it resolves my problem.
So I did that, and it solved the 2 issues, the compilation error, and the runtime error.
for me I had to remove a package that was corrupted. c:\src\flutter.pub-cache\hosted\pub.dartlang.org\localstorage-4.0.0+1 Apparently, a file had become corrupted by me invertly. I removed the package and did a flutter pub get then recompiled and it worked.