DataTable中的Flutter DropdownButton,列表中的DropdownButton选项 [英] Flutter DropdownButton in DataTable, DropdownButton options from list

查看:268
本文介绍了DataTable中的Flutter DropdownButton,列表中的DropdownButton选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扑朔迷离中,我试图将DataTable的列之一作为DropdownButton。我希望最初从getUsers填充DataTable行,然后能够使用基于ratingList的DropdownButton编辑单元格。


所以我希望能够更改DropdownButton单元格的值应为ratingList中的任何值:['Ok','Good','Great','Amazing'];注意,我希望能够选择'Great'或'Amazing',这些不是初始填充值之一。


从getUsers加载数据非常重要,因为最终会从Firestore那里抢到。然后,有能力在加载数据后根据ratingList值(一个完整的评级列表)更改DropdownButton单元。


请参见以下示例代码(DropdownButton不会't更改单元格值),也可以在

解决方案

只需将 user.rating = newValue 放入 setState 块中。


就像

  onChanged :(字符串newValue){
setState((){
// help!
user.rating = newValue;
});
},


In flutter I'm trying to have one of the columns of a DataTable be a DropdownButton. I would like the DataTable rows to populate from getUsers initially, then be able to edit the cell cell with a the DropdownButton based on the ratingList.

So I would like to be able to change the value of the DropdownButton cell to any of the values in the ratingList: ['Ok', 'Good', 'Great', 'Amazing']; Note I want to be able to select 'Great' or 'Amazing', these aren't one of the initial populated values.

It is essential for the data to be loaded from getUsers, as this will be grabbed from Firestore eventually. Then have the ability to change a DropdownButton cell after the data is loaded, based on the ratingList of values, which is a complete list of the ratings.

See below for example code (DropdownButton doesn't change cell value), also in DartPad.

Thanks in advance!

解决方案

Just put user.rating = newValue into setState block.

Like this.

onChanged: (String newValue) {
    setState(() {
        //help!
        user.rating = newValue;
    });
},

这篇关于DataTable中的Flutter DropdownButton,列表中的DropdownButton选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆