Flutter 在Flatter中序列化扩展类时未定义名称

Flutter 在Flatter中序列化扩展类时未定义名称,flutter,Flutter,在我正在开发的颤振应用程序中,我有以下课程。其目的是使一个可继承的类可包含,该类按项和其他一些类似的类进行扩展,所有这些类都生成相同的错误,可序列化的成员作为祖先类的一部分: includedcondition.dart: import 'package:json_annotation/json_annotation.dart'; part 'includecondition.g.dart'; @JsonSerializable() class IncludeCondition { St

在我正在开发的颤振应用程序中,我有以下课程。其目的是使一个可继承的类可包含,该类按项和其他一些类似的类进行扩展,所有这些类都生成相同的错误,可序列化的成员作为祖先类的一部分:

includedcondition.dart:

import 'package:json_annotation/json_annotation.dart';

part 'includecondition.g.dart';

@JsonSerializable()
class IncludeCondition {
  String property;
  String condition;
  String selection;
  String value;

  IncludeCondition({this.property, this.condition, this.selection, this.value});

  // Serialization Methods
  factory IncludeCondition.fromJson(Map<String, dynamic> json) =>
      _$IncludeConditionFromJson(json);
  Map<String, dynamic> toJson() => _$IncludeConditionToJson(this);
}
inclusible.dart:

import 'package:randomizer/model/includecondition.dart';
import 'package:randomizer/model/setup.dart';

abstract class Includable {
  List<IncludeCondition> includedWhen;
  List<IncludeCondition> includedIf;
  List<IncludeCondition> mustIncludeWhen;
  List<IncludeCondition> excludeWhen;

  Includable();
}
项目.省道:

import 'package:randomizer/model/includable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:randomizer/model/includecondition.dart';

part 'item.g.dart';

@JsonSerializable()
class Item extends Includable {
  String name;

  Item({this.name, this.expansion, this.playerMin, this.playerMax, this.cost});

  // Serialization Methods
  factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);
  Map<String, dynamic> toJson() => _$ItemToJson(this);
}
构建项目时,我在item.g.dart类中获得了未定义的名称“IncludeCondition”,其代码如下:

Item _$ItemFromJson(Map<String, dynamic> json) {
  return Item(
      name: json['name'] as String,
    ..includedWhen = (json['includedWhen'] as List)
        ?.map((e) => e == null
            ? null
            : IncludeCondition.fromJson(e as Map<String, dynamic>))
        ?.toList()
    ..includedIf = (json['includedIf'] as List)
        ?.map((e) => e == null
            ? null
            : IncludeCondition.fromJson(e as Map<String, dynamic>))
        ?.toList()
    ..mustIncludeWhen = (json['mustIncludeWhen'] as List)
        ?.map((e) => e == null
            ? null
            : IncludeCondition.fromJson(e as Map<String, dynamic>))
        ?.toList()
    ..excludeWhen = (json['excludeWhen'] as List)
        ?.map((e) => e == null
            ? null
            : IncludeCondition.fromJson(e as Map<String, dynamic>))
        ?.toList();
}

如何消除此错误?

只需导入“includedcondition.dart;”在item.dart文件中

我已更新了我的列表,但该导入已包含在item.dart中。