簡體   English   中英

超級構造函數語法問題 - 錯誤:沒有具有名稱的命名參數

[英]Super constructor syntax issues - Error: No named parameter with the name

我正在嘗試運行其他開發人員的現有代碼。 它向我展示了這個奇怪的錯誤:

Xcode 的 output:

lib/ui/ActHospitalDetail.dart:171:25: Error: No named parameter with the name 'itemBuilder'.
                        itemBuilder: (context, _) => Icon(
                        ^^^^^^^^^^^
../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_rating_bar-3.2.0+1/lib/src/rating_bar.dart:31:9: Context: Found this candidate, but the arguments don't match.
  const RatingBar({
        ^^^^^^^^^

這是相關的代碼。 呼叫者,召集者:

Row(
  children: <Widget>[
    RatingBar(
      itemSize: ScreenUtil().setWidth(15),
      initialRating: double.parse(provider.hospitalDetailModel.data.avgRating),
      minRating: 0,
      direction: Axis.horizontal,
      allowHalfRating: true,
      itemCount: 5,
      ignoreGestures: true,
      unratedColor: Color(clrGreyLight),
      //itemPadding: EdgeInsets.symmetric(horizontal: 1.0),
      itemBuilder: (context, _) => Icon(
        Icons.star,
        color: Color(clrYellow),
      ),
      onRatingUpdate: (rating) {
        print(rating);
      },
    ),
    SizedBox(width: ScreenUtil().setWidth(2),),
    Text(provider.hospitalDetailModel.data.avgRating, style: TextStyle(fontSize: ScreenUtil().setSp(14), color: Color(clrYellow), fontWeight: FontWeight.bold) ,),
    SizedBox(width: ScreenUtil().setWidth(1),),
    RichText(
      text: TextSpan(
        text: "(" + provider.hospitalDetailModel.data.totalRating + " ",
        style: TextStyle(fontSize: ScreenUtil().setSp(12), color: Color(clrGreyLight), fontWeight: FontWeight.bold),
        children: <TextSpan>[
          TextSpan(text: "${AppTranslations.of(context).text((int.parse(provider.hospitalDetailModel.data.totalRating) > 1) ? "Ratings" : "Rating")}" + ")", style: TextStyle(fontWeight: FontWeight.bold)),
        ]
      ),
    ),
    //Text("(278 ratings)", style: TextStyle(fontSize: ScreenUtil().setSp(12), color: Color(clrGreyLight), fontWeight: FontWeight.bold) ,),
  ],
),

“itemBuilder”帶有紅色下划線,並在我對其進行 hover 時顯示此建議:

未定義命名參數“itemBuilder”。 (文檔)
嘗試將名稱更正為現有命名參數的名稱,或使用名稱“itemBuilder”定義命名參數。

構造函數:

const RatingBar.builder({
    /// {@template flutterRatingBar.itemBuilder}
    /// Widget for each rating bar item.
    /// {@endtemplate}
    @required IndexedWidgetBuilder itemBuilder,
    @required this.onRatingUpdate,
    this.glowColor,
    this.maxRating,
    this.textDirection,
    this.unratedColor,
    this.allowHalfRating = false,
    this.direction = Axis.horizontal,
    this.glow = true,
    this.glowRadius = 2,
    this.ignoreGestures = false,
    this.initialRating = 0.0,
    this.itemCount = 5,
    this.itemPadding = EdgeInsets.zero,
    this.itemSize = 40.0,
    this.minRating = 0,
    this.tapOnlyMode = false,
    this.updateOnDrag = false,
    this.wrapAlignment = WrapAlignment.start,
  })  : _itemBuilder = itemBuilder,
        _ratingWidget = null;

這種錯誤也出現在許多其他代碼片段中。 這些片段之間的共同點是所有這些未定義的參數(如 itemBuilder)都顯示在超級構造函數中。

那么,我的 flutter 版本是否無法識別這種構造函數聲明的語法? 因為它在以前的開發人員工作站上工作得很好。

歡迎任何想法或建議。

謝謝

在他的情況下,您必須將構造稱為RatingBar.builder ,而不僅僅是RatingBar

例子:

RatingBar.builder(
  itemSize: ScreenUtil().setWidth(15),
  initialRating: double.parse(provider.hospitalDetailModel.data.avgRating),
...

請注意,您顯示的構造函數被聲明為命名構造函數。

const RatingBar.builder({

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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