简体   繁体   English

数据表中的 Flutter DropdownButton,列表中的 DropdownButton 选项

[英]Flutter DropdownButton in DataTable, DropdownButton options from list

In flutter I'm trying to have one of the columns of a DataTable be a DropdownButton.在颤动中,我试图将 DataTable 的列之一设为 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.我希望最初从 getUsers 填充 DataTable 行,然后能够使用基于 ratingList 的 DropdownButton 编辑单元格单元格。

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'];所以我希望能够将 DropdownButton 单元格的值更改为 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.从 getUsers 加载数据是必不可少的,因为这最终会从 Firestore 中获取。 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.然后有能力在数据加载后更改 DropdownButton 单元格,基于值的 ratingList,这是一个完整的评级列表。

See below for example code (DropdownButton doesn't change cell value), also in DartPad.请参阅下面的示例代码(DropdownButton 不会更改单元格值),也在DartPad 中。

Thanks in advance!提前致谢!

在此处输入图片说明

Just put user.rating = newValue into setState block.只需将user.rating = newValue放入setState块。

Like this.像这样。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM