我有一个变量title
,我用一个字符串值对其进行了初始化。
class NameState{
List name;
var title = 'this is a default one';
NameState({this.title,this.name});
NameState copyWith({title, name}) {
print(title); // this one should be null as there is no data.
print(this.title); // null => why this one null as i have title defined
return new NameState(
title: title ?? this.title,
name: name ?? this.name,
);
}
}
这里的title
变量有一个值。但是如果我在构造函数中未传递title的任何值,则this.title
的值将为null。如何获得this is a default one
中的当前值this.title
?
谢谢。
答案 0 :(得分:1)
您需要使用此
$userBasicInfo->affiliatedFacilities()->sync($request->get('affiliated_facility', []));
代替
NameState({this.title = 'this is a default one', this.name});