元素类型; list< dropdownmenuitem< double>>>'可以将列表类型分配给列表类型。
当我尝试自动化作为 DropDownButton 一部分的项目时,我遇到了问题。 每次我尝试执行下面的函数时,我都会收到此错误:元素类型“List
我尝试不使用地图功能,并按照 Flutter 官方页面描述如何使用下拉按钮的方式进行操作,但没有任何改变。我遇到了同样的错误。
class DataHelper {
static List<String> tumDerslerinHarflerii() {
return ["AA", "BA", "BB", "CB", "CC", "CD", "DD", "FD", "FF"];
}
static double? harfiNotaCevir(String harf) {
switch (harf) {
case "AA":
return 4;
case "BA":
return 3.5;
case "BB":
return 3.0;
case "CB":
return 2.5;
case "CC":
return 2;
case "DC":
return 1.5;
case "DD":
return 1.0;
case "FD":
return 0.5;
case "FF":
return 0.0;
}
return null;
}
static List<DropdownMenuItem<double>> tumDerslerinHarfleri() {
return tumDerslerinHarflerii()
.map(
(e) => DropdownMenuItem(
child: Text("$e"),
value: harfiNotaCevir(e),
),
)
.toList();
}
}
我在 DropDownWidget 中使用它:
_buildHarfler(GlobalKey buildHarfKey, double _value) {
return Container(
decoration: BoxDecoration(
color: Sabitler.anaRenk.withOpacity(0.3),
borderRadius: Sabitler.borderRadius,
),
child: DropdownButton<double>(
key: buildHarfKey,
value: _value,
items: [
// Dropdown içindeki elementlerin her biri bir widget; liste istiyor.
DataHelper.tumDerslerinHarfleri(),
],
onChanged: (secilenDeger) {
_value = secilenDeger!;
},
),
);
}
I'm having a problem when ı try to automatize my Items which is a part of DropDownButton.
Every time ı try to execute the function below ı get this error:The element type 'List<DropdownMenuItem>' can't be assigned to the list type 'DropdownMenuItem'.
I tried not to use map function and did the same as Flutter's official page that describes how to use a dropdown button but nothing has changed. I got the same error.
class DataHelper {
static List<String> tumDerslerinHarflerii() {
return ["AA", "BA", "BB", "CB", "CC", "CD", "DD", "FD", "FF"];
}
static double? harfiNotaCevir(String harf) {
switch (harf) {
case "AA":
return 4;
case "BA":
return 3.5;
case "BB":
return 3.0;
case "CB":
return 2.5;
case "CC":
return 2;
case "DC":
return 1.5;
case "DD":
return 1.0;
case "FD":
return 0.5;
case "FF":
return 0.0;
}
return null;
}
static List<DropdownMenuItem<double>> tumDerslerinHarfleri() {
return tumDerslerinHarflerii()
.map(
(e) => DropdownMenuItem(
child: Text("$e"),
value: harfiNotaCevir(e),
),
)
.toList();
}
}
And I'm using it in my DropDownWidget:
_buildHarfler(GlobalKey buildHarfKey, double _value) {
return Container(
decoration: BoxDecoration(
color: Sabitler.anaRenk.withOpacity(0.3),
borderRadius: Sabitler.borderRadius,
),
child: DropdownButton<double>(
key: buildHarfKey,
value: _value,
items: [
// Dropdown içindeki elementlerin her biri bir widget; liste istiyor.
DataHelper.tumDerslerinHarfleri(),
],
onChanged: (secilenDeger) {
_value = secilenDeger!;
},
),
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
DataHelper.tumDerslerinHarfleri(),
更改为...DataHelper.tumDerslerinHarfleri(),
这将在列表中添加来自您的函数的项目 (
tumDerslerinHarfleri
) 到DropdownButton
的items
change
DataHelper.tumDerslerinHarfleri(),
to...DataHelper.tumDerslerinHarfleri(),
this will add the items in the list that are coming from your function (
tumDerslerinHarfleri
) to theitems
of yourDropdownButton
你需要传播你的清单。
[...DataHelper.tumDerslerinHarfleri()]
You need to spread you list.
[...DataHelper.tumDerslerinHarfleri()]