我在项目中使用builtvalue
我有一个json
,看起来如下
{ "status": 1, "msg": "Success", "data": [ { "feeID": "25", "collectionID": "0", "type": 1, "category": "3 Fee", "schemeInfo": { "schemeID": 0, "schemeNo": 0, "schemeTxt": "", "schemeStatus": 1 }, "feeCode": "ISter Fee", "feeShortName": "", "basicAMT": "120000", "scholarshipInfo": { "scholarship": "0", "scholarshipAMT": 0, "scholarshipIDs": [] }, "dueDate": "2018-05-10", "lateFeeInfo": { "lateFeePerDay": "0", "lateDays": 28, "lateFeeAMT": 0 }, "taxInfo": { "tax": "18", "taxAMT": 21600, "taxAddedAMT": 141600 }, "grandAMT": 141600, "status": "2", "dateStatus": "1", "collectionDetailStatus": -1 }, { "feeID": "54", "collectionID": "0", "type": 1, "category": "4th Semester Tuition Fee", "schemeInfo": { "schemeID": 0, "schemeNo": 0, "schemeTxt": "", "schemeStatus": 1 }, "feeCode": "ISion Fee", "feeShortName": "", "basicAMT": "120000", "scholarshipInfo": { "scholarship": "0", "scholarshipAMT": 0, "scholarshipIDs": [] }, "dueDate": "2018-10-30", "lateFeeInfo": { "lateFeePerDay": "0", "lateDays": 28, "lateFeeAMT": 0 }, "taxInfo": { "tax": "18", "taxAMT": 21600, "taxAddedAMT": 141600 }, "grandAMT": 141600, "status": "2", "dateStatus": "1", "collectionDetailStatus": -1 } ], "wallet": { "walletID": "1483", "walletNo": "", "NTB": "25000.00", "WAB": "0.00", "status": "empty" } }
以下是我使用builtvalue
的模型类
library fee_model;
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
part 'fee_model.g.dart';
abstract class FeeModel implements Built<FeeModel,FeeModelBuilder> {
FeeModel._();
factory FeeModel([updates(FeeModelBuilder b)]) = _$FeeModel;
@nullable
@BuiltValueField(wireName: 'status')
int get status;
@nullable
@BuiltValueField(wireName: 'msg')
String get msg;
@nullable
@BuiltValueField(wireName: 'data')
BuiltList get data;
@nullable
@BuiltValueField(wireName: 'wallet')
Wallet get wallet;
static Serializer get serializer => _$feeModelSerializer;
}
abstract class FeeData implements Built<FeeData, FeeDataBuilder> {
FeeData._();
factory FeeData([updates(FeeDataBuilder b)]) = _$FeeData;
@nullable
@BuiltValueField(wireName: 'feeID')
String get feeID;
@nullable
@BuiltValueField(wireName: 'collectionID')
String get collectionID;
@nullable
@BuiltValueField(wireName: 'type')
int get type;
@nullable
@BuiltValueField(wireName: 'schemeInfo')
SchemeInfo get schemeInfo;
@nullable
@BuiltValueField(wireName: 'category')
String get category;
@nullable
@BuiltValueField(wireName: 'feeCode')
String get feeCode;
@nullable
@BuiltValueField(wireName: 'feeShortName')
String get feeShortName;
@nullable
@BuiltValueField(wireName: 'basicAMT')
String get basicAMT;
@nullable
@BuiltValueField(wireName: 'scholarshipInfo')
ScholarshipInfo get scholarshipInfo;
@nullable
@BuiltValueField(wireName: 'dueDate')
String get dueDate;
@nullable
@BuiltValueField(wireName: 'lateFeeInfo')
LateFeeInfo get lateFeeInfo;
@nullable
@BuiltValueField(wireName: 'taxInfo')
TaxInfo get taxInfo;
@nullable
@BuiltValueField(wireName: 'grandAMT')
double get grandAMT;
@nullable
@BuiltValueField(wireName: 'status')
String get status;
@nullable
@BuiltValueField(wireName: 'dateStatus')
String get dateStatus;
@nullable
@BuiltValueField(wireName: 'collectionDetailStatus')
int get collectionDetailStatus;
static Serializer get serializer => _$feeDataSerializer;
}
abstract class Wallet implements Built<Wallet,WalletBuilder> {
Wallet._();
factory Wallet([updates(WalletBuilder wb)]) = _$Wallet;
@nullable
@BuiltValueField(wireName: 'walletID')
String get walletID;
@nullable
@BuiltValueField(wireName: 'walletNo')
String get walletNo;
@nullable
@BuiltValueField(wireName: 'NTB')
String get nTB;
@nullable
@BuiltValueField(wireName: 'WAB')
String get wAB;
@nullable
@BuiltValueField(wireName: 'status')
String get status;
static Serializer get serializer => _$walletSerializer;
}
abstract class SchemeInfo implements Built<SchemeInfo,SchemeInfoBuilder>{
SchemeInfo._();
factory SchemeInfo([updates(SchemeInfo si)]) = _$SchemeInfo;
@nullable
@BuiltValueField(wireName: 'schemeID')
int get schemeID;
@nullable
@BuiltValueField(wireName: 'schemeNo')
int get schemeNo;
@nullable
@BuiltValueField(wireName: 'schemeTxt')
String get schemeTxt;
@nullable
@BuiltValueField(wireName: 'schemeStatus')
int get schemeStatus;
static Serializer get serializer =>
_$schemeInfoSerializer;
}
abstract class ScholarshipInfo implements Built<ScholarshipInfo,ScholarshipInfoBuilder> {
ScholarshipInfo._();
factory ScholarshipInfo([updates(ScholarshipInfo si)]) = _$ScholarshipInfo;
@nullable
@BuiltValueField(wireName: 'scholarship')
String get scholarship;
@nullable
@BuiltValueField(wireName: 'scholarshipAMT')
int get scholarshipAMT;
@nullable
@BuiltValueField(wireName: 'scholarshipIDs')
BuiltList get scholarshipIDs;
static Serializer get serializer => _$scholarshipInfoSerializer;
}
abstract class LateFeeInfo implements Built<LateFeeInfo, LateFeeInfoBuilder>{
LateFeeInfo._();
factory LateFeeInfo([updates(LateFeeInfo lfi)]) = _$LateFeeInfo;
@nullable
@BuiltValueField(wireName: 'lateFeePerDay')
String get lateFeePerDay;
@nullable
@BuiltValueField(wireName: 'lateDays')
int get lateDays;
@nullable
@BuiltValueField(wireName: 'lateFeeAMT')
int get lateFeeAMT;
static Serializer get serializer => _$lateFeeInfoSerializer;
}
abstract class TaxInfo implements Built<TaxInfo,TaxInfoBuilder>{
TaxInfo._();
factory TaxInfo([updates(TaxInfo ti)]) = _$TaxInfo;
@nullable
@BuiltValueField(wireName: 'tax')
String get tax;
@nullable
@BuiltValueField(wireName: 'taxAMT')
double get taxAMT;
@nullable
@BuiltValueField(wireName: 'taxAddedAMT')
double get taxAddedAMT;
static Serializer get serializer => _$taxInfoSerializer;
}
我运行了命令flutter packages pub run build_runner build
,然后我也得到了错误提示redirected construcot has incompatible parameters
我已附上屏幕截图
我在SchemeInfo,ScholarshipInfo,LateFeeInfo,TaxInfo
上一直收到错误,但在Wallet,FeeData,FeeModel
上却没有收到错误
我不确定这是builtvalue
库本身中的错误,还是我做错了什么,因为我也在项目中创建了其他模型类,并且在没有上述错误的情况下它们运行良好
答案 0 :(得分:2)
如错误消息所述
factory SchemeInfo([updates(SchemeInfo si)]) = _$SchemeInfo;
应该是
factory SchemeInfo([updates(SchemeInfoBuilder si)]) = _$SchemeInfo;