我想创建一个嵌套对象以请求发送给api。非常感谢帮助。
下面是嵌套的构建值类
abstract class BuiltUpdateProfileRequest
implements
Built<BuiltUpdateProfileRequest, BuiltUpdateProfileRequestBuilder> {
// fields go here
String get firstName;
String get lastName;
String get phoneNumber;
@nullable
ProfileBilling get billing;
BuiltUpdateProfileRequest._();
factory BuiltUpdateProfileRequest(
[updates(BuiltUpdateProfileRequestBuilder b)]) =
_$BuiltUpdateProfileRequest;
static Serializer<BuiltUpdateProfileRequest> get serializer =>
_$builtUpdateProfileRequestSerializer;
}
abstract class ProfileBilling
implements Built<ProfileBilling, ProfileBillingBuilder> {
// fields go here
@nullable
String get address1;
@nullable
String get address2;
@nullable
String get city;
@nullable
String get state;
@nullable
String get country;
@nullable
String get zip;
ProfileBilling._();
factory ProfileBilling([updates(ProfileBillingBuilder b)]) = _$ProfileBilling;
static Serializer<ProfileBilling> get serializer =>
_$profileBillingSerializer;
}
以下是请求对象,但在电话号码下开票时引发错误,指出无法将Profile Profile Billing类型的值分配给ProfileBillingBuilder类型的变量。
final ProfileBilling profileBilling = ProfileBilling((b) => b
..address1 = ""
..address2 = ""
..city = ""
..state = ""
..country = ""
..zip = "");
final BuiltUpdateProfileRequest builtUpdateProfileRequest =
BuiltUpdateProfileRequest((b) => b
..firstName = firstName
..lastName = lastName
..phoneNumber = phoneNo
..billing = profileBilling);
您需要调用该方法toBuilder()
来创建ProfileBillingBuilder变量;
final BuiltUpdateProfileRequest builtUpdateProfileRequest =
BuiltUpdateProfileRequest((b) => b
..firstName = firstName
..lastName = lastName
..phoneNumber = phoneNo
..billing = profileBilling.toBuilder());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句