Chris
Chris

Reputation: 175

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. 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!

enter image description here

Upvotes: 0

Views: 489

Answers (1)

XC.xc
XC.xc

Reputation: 101

Just put user.rating = newValue into setState block.

Like this.

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

Upvotes: 1

Related Questions