未在 Flutter(Dart) 中创建 .g.dart 类

问题描述 投票:0回答:1

我在

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
类。

终端中给出的错误图像: terminal error

flutter dart terminal annotations json-serialization
1个回答
0
投票

您缺少一个分号来关闭 AppData 构造函数:

AppData({this.Username, this.Password, this.Email,this.Family, this.Name, this.FullName, this.UserType, this.Mobile, this.Avatar});

© www.soinside.com 2019 - 2024. All rights reserved.