json_serializable问题
来源:3-10 三种JSON解析技巧带你解放生产力

weixin_慕UI2387872
2024-02-29
老师,在执行命令:flutter packages pub run build_runner build
build生成实体类时候,出现了问题,求解
依赖版本:
dependencies:
dio: ^5.4.1
json_annotation: ^4.8.1
dev_dependencies:
json_serializable: ^6.7.1
build_runner: ^2.4.8
result.dart
import 'package:json_annotation/json_annotation.dart';
part 'result.g.dart';
@JsonSerializable()
class Result {
// 定义字段
int? code;
String? method;
String? requestParams;
Result(this.code, this.method, this.requestParams);
// 固定格式,不同的类使用不同的mixin即可
factory Result.fromJson(Map<String, dynamic> json) => _$ResultFromJson(json);
Map<String, dynamic> toJson() => _$ResultToJson(this);
}
报错:
Deprecated. Use `dart run` instead.
Building package executable... (2.0s)
Failed to build build_runner:build_runner:
../../.pub-cache/hosted/pub.flutter-io.cn/dart_style-2.3.5/lib/src/source_visitor.dart:595:19: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'.
- 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.flutter-io.cn/analyzer-6.2.0/lib/src/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'.
modifier(node.macroKeyword);
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.flutter-io.cn/dart_style-2.3.5/lib/src/front_end/ast_node_visitor.dart:251:16: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'.
- 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.flutter-io.cn/analyzer-6.2.0/lib/src/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'.
node.macroKeyword,
^^^^^^^^^^^^
写回答
1回答
-
CrazyCodeBoy
2024-02-29
你将flutter和json_serializable以及build_runner都升级到最新版看看还有没有这个问题012024-03-01
相似问题
Route定义问题
回答 1
安卓打包时遇到的问题
回答 2