[英]What is {} mark at constructors in Flutter and Dart
My code :我的代码:
class aaa {
String a ;
aaa.n1({String a1}){ // erase {} here.No error
// aaa.n1(String a1){ // No error
this.a = a1 ;
print(a1) ;
}
}
class bbb extends aaa {
bbb.n1(String uu) : super.n1('y') ; //compile and error here (at 'y' letter)
}
void main() {
bbb a = new bbb.n1('hhhhhhhh');
print(a.a);
}
The error : Too many positional arguments: 0 allowed, but 1 found.错误:位置参数太多:0 允许,但 1 找到。 Try removing the extra positional arguments.尝试删除额外的位置参数。 bbb.n1(String uu) : super.n1('y') ; bbb.n1(String uu) : super.n1('y') ;
I imitate at https://api.flutter.dev/flutter/widgets/Center-class.html like that我在https://api.flutter.dev/flutter/widgets/Center-class.html模仿
Center({Key key, double widthFactor, double heightFactor, Widget child }) Center({Key key, double widthFactor, double heightFactor, Widget child })
Why do they use {} mark .他们为什么使用 {} 标记。 Doesn't it ({}) meaning ?不是 ({}) 的意思吗?
{}
is used for named arguments, which means you have to specify the argument name to which you want to specify the value. {}
用于命名参数,这意味着您必须指定要为其指定值的参数名称。
In the below code the name is a1
and the value is y
.在下面的代码中,名称是a1
,值是y
。
class bbb extends aaa {
bbb.n1(String uu) : super.n1(a1: 'y') ; //compile and error here (at 'y' letter)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.