Hi Marcio,
As per the DataGrid new API structure, you can load the Dropdown button widget to the corresponding cell of DataGridRowAdaptor in the DataGridSource.buildRow method. We have documented all the breaking changes and its alternate APIs in below blog,
Code Snippet:
|
@override
DataGridRowAdapter? buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((dataGridCell) {
return Container(
alignment: (dataGridCell.columnName == 'id' ||
dataGridCell.columnName == 'salary')
? Alignment.centerRight
: Alignment.centerLeft,
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: dataGridCell.columnName == 'designation'
? DropdownButton<String>(
value: dropdownvalue,
items: items.map((String items) {
return DropdownMenuItem(
value: items,
child: Text(items),
);
}).toList(),
onChanged: (String? newValue) {
dropdownvalue = newValue!;
_employees[2].designation = newValue;
notifyListeners();
})
: Text(
dataGridCell.value.toString(),
overflow: TextOverflow.ellipsis,
));
}).toList());
} |
Also, we have prepared the sample with the editing feature for that, you can tap the ship country or ship city column cells to select the value from the dropdown. Please check the following sample,
We hope this helps. Please let us know if you need any further assistance.
Regards,
Tamilarasan