我在
flutter中使用了
json_serializable
库并创建了一个类并创建了库的Annotation
,即类中的json_serialized,如下例所示:
import 'package:json_annotation/json_annotation.dart';
part 'AppData.g.dart';
@JsonSerializable()
class AppData {
String? Username;
String? Password;
String? Avatar;
String? Name;
String? Family;
String? FullName;
String? UserType;
String? Email;
String? Mobile;
AppData({this.Username, this.Password, this.Email,
this.Family, this.Name, this.FullName, this.UserType, this.Mobile, this.Avatar})
factory AppData.fromJson(Map<String, dynamic> json) =>
_$AppDataFromJson(json);
Map<String, dynamic> toJson() => _$AppDataToJson(this);
}
问题是,当我在
terminal中输入
dart run build_runner build
时,它会给出错误并且不会创建 AppData.g.dart
类。
您缺少一个分号来关闭 AppData 构造函数:
AppData({this.Username, this.Password, this.Email,this.Family, this.Name, this.FullName, this.UserType, this.Mobile, this.Avatar});