绘制下拉按钮未显示值
我正在尝试进行平均坡度的应用。在我的控制器页面中,我在下面有此代码。我要做的只是在下拉式控制器中显示此数据。我已经工作了几个小时,但是我无法按预期运行它,这里有什么问题?你能帮忙吗?预先感谢
这是控制器页面
class Controller extends GetxController {
var liste = ["AA", "BA", "BB", "CB", "CC", "DC", "DD", "FD", "FF"];
convertToDropdownMenuItem() {
return liste
.map((e) => DropdownMenuItem(
value: convertLettersToGrade(e),
child: Text(e),
))
.toList();
}
convertLettersToGrade(String e) {
switch (e) {
case "AA":
return 4;
case "BA":
return 3.5;
case "BB":
return 3;
case "CB":
return 2.5;
case "CC":
return 2;
case "DC":
return 1.5;
case "DD":
return 1;
case "FD":
return 0.5;
case "FF":
return;
}
}
,这是我的主屏幕
Container(
color:Colors.grey,
child: DropdownButton<double>(
value: val,
items: controller.convertToDropdownMenuItem(),
onChanged: (newVal) {
setState(() {
val = newVal!;
print(controller.convertToDropdownMenuItem());//Data comes poperly here
});
},
I am trying to make a grade point average application. In my controller page I have this code below. What I am trying to do is just display this data in the Dropdown controller.I have been working on for hours but I couldn't make it run as expected What is wrong here? Could you please help? Thanks in advance
This is the Controller page
class Controller extends GetxController {
var liste = ["AA", "BA", "BB", "CB", "CC", "DC", "DD", "FD", "FF"];
convertToDropdownMenuItem() {
return liste
.map((e) => DropdownMenuItem(
value: convertLettersToGrade(e),
child: Text(e),
))
.toList();
}
convertLettersToGrade(String e) {
switch (e) {
case "AA":
return 4;
case "BA":
return 3.5;
case "BB":
return 3;
case "CB":
return 2.5;
case "CC":
return 2;
case "DC":
return 1.5;
case "DD":
return 1;
case "FD":
return 0.5;
case "FF":
return;
}
}
And this my home screen
Container(
color:Colors.grey,
child: DropdownButton<double>(
value: val,
items: controller.convertToDropdownMenuItem(),
onChanged: (newVal) {
setState(() {
val = newVal!;
print(controller.convertToDropdownMenuItem());//Data comes poperly here
});
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚在Switch stapement的结尾添加了此内容
,然后将其更改
为
,它像魅力一样工作
I just added this at the end of switch statemement
and change this
to
and it worked like a charm