gpt4 book ai didi

flutter - 如何使用内置值创建嵌套对象

转载 作者:行者123 更新时间:2023-12-03 03:20:39 24 4
gpt4 key购买 nike

我想创建一个嵌套对象以请求发送给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());

关于flutter - 如何使用内置值创建嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63426729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com