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

generated xxx.g.dart error #1027

Closed
gaohongliang opened this issue Dec 26, 2023 · 2 comments
Closed

generated xxx.g.dart error #1027

gaohongliang opened this issue Dec 26, 2023 · 2 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@gaohongliang
Copy link

gaohongliang commented Dec 26, 2023

@Freezed(genericArgumentFactories:true)
class Response<T> with _$Response<T> {
  const factory Response({
    @JsonKey(name: 'RequestId') required String requestId,
    @JsonKey(name: 'Error') required Error? error,
    @JsonKey(name: 'Data') dynamic data,
  }) = _Response<T>;

  factory Response.fromJson(Map<String, Object?> json, T Function(dynamic) fromJsonT) =>
      _$ResponseFromJson<T>(json,fromJsonT);
}

@Freezed(genericArgumentFactories: true)
class ServerResponse<T> with _$ServerResponse<T> {
  const factory ServerResponse({
    @JsonKey(name: 'Response') required Response<T> response,
  }) = _ServerResponse<T>;

  factory ServerResponse.fromJson(
          Map<String, Object?> json, T Function(dynamic) fromJsonT) =>
      _$ServerResponseFromJson<T>(json, fromJsonT);
}

execute this command
dart run build_runner build

class Response generated succes,but ServerResponse failed.

[INFO] Generating build script completed, took 451ms
[INFO] Reading cached asset graph completed, took 294ms
[INFO] Checking for updates since last build completed, took 1.4s
[SEVERE] json_serializable on lib/models/server_response.dart:

RangeError (index): Invalid value: Only valid value is 0: -1
[INFO] Running build completed, took 2.6s
[INFO] Caching finalized dependency graph completed, took 192ms
@rrousselGit
Copy link
Owner

Duplicate of #887

@rrousselGit rrousselGit marked this as a duplicate of #887 Dec 26, 2023
@dwkim891220
Copy link

i hope this comment help you
#766 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants