我正在尝试运行其他开发人员的现有代码。它向我展示了这个奇怪的错误:
Xcode 的输出:
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”带有红色下划线,当我将鼠标悬停在它上面时会显示此建议:
未定义命名参数“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({
我也遇到过像你一样的问题。我所做的就是删除我的 pubspec.lock 并再次运行“flutter pub get”。那么问题就全部解决了