Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes not being generated with class-modifiers #1302

Closed
JosephNK opened this issue Feb 21, 2024 · 3 comments
Closed

Classes not being generated with class-modifiers #1302

JosephNK opened this issue Feb 21, 2024 · 3 comments

Comments

@JosephNK
Copy link

JosephNK commented Feb 21, 2024

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.0, on macOS 13.4 22F66 darwin-x64, locale ko-KR)
... ...
...

Dependency Info
- built_value: ^8.9.1
- build_runner: ^2.4.8
- built_value_generator: ^8.9.1
- analyzer: ^6.4.1

api_service_response.dart

part 'api_service_response.g.dart';

@BuiltValue(instantiable: false)
abstract class APIServiceResponse extends Object with APIServiceResponseValues {
  APIServiceResponse rebuild(void Function(APIServiceResponseBuilder) updates);
  APIServiceResponseBuilder toBuilder();
}

mixin APIServiceResponseValues {
  @BuiltValueField(wireName: 'status_cd')
  String? get statusCd;
  ...
}
$ dart pub run build_runner build --delete-conflicting-outputs

[SEVERE] built_value_generator:built_value on lib/src/services/response/base/api_service_response.dart (cached):
An error `FormatterException` occurred while formatting the generated source for
  `package:flutter_nano_chatbot/src/services/response/base/api_service_response.dart`
which was output to
  `lib/src/services/response/base/api_service_response.built_value.g.part`.
This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:

line 7, column 10 of .: This requires the 'class-modifiers' language feature to be enabled.
  ╷
7 │ abstract mixin class APIServiceResponseBuilder {
  │          ^^^^^

Is there a solution?

@JosephNK
Copy link
Author

I succeeded by using the @dart directive as shown below.
I don't know if this is the right way.
Is there any other way?

// @dart = 2.18
import 'package:built_value/built_value.dart';

part 'api_service_response.g.dart';

@BuiltValue(instantiable: false)
abstract class APIServiceResponse extends Object with APIServiceResponseValues {
  APIServiceResponse rebuild(void Function(APIServiceResponseBuilder) updates);
  APIServiceResponseBuilder toBuilder();
}
... ...
...

@JosephNK JosephNK changed the title The class modifier does not create a class. Classes not being generated with class-modifiers Feb 22, 2024
@JosephNK
Copy link
Author

I tried again after removing the pubspec.lock file and it worked.
There seems to have been an issue with dart 3.0 in pubspec dependencies.

@davidmorgan
Copy link
Collaborator

Interesting! Not sure how that happened. If you (or anyone else reading this) figure out a way to repro, please let me know. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants