簡體   English   中英

Flutter 和 Dart 中的構造函數中的 {} 標記是什么

[英]What is {} mark at constructors in Flutter and Dart

我的代碼:

 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);
}

錯誤:位置參數太多:0 允許,但 1 找到。 嘗試刪除額外的位置參數。 bbb.n1(String uu) : super.n1('y') ;

我在https://api.flutter.dev/flutter/widgets/Center-class.html模仿

Center({Key key, double widthFactor, double heightFactor, Widget child })

他們為什么使用 {} 標記。 不是 ({}) 的意思嗎?

{}用於命名參數,這意味着您必須指定要為其指定值的參數名稱。

在下面的代碼中,名稱是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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM