onRowSave property

List? Function(int index, List oldValue, List newValue)? onRowSave
final

Called when the user clicks on the save icon of a row.

Return List

The newValue must be a list of the same length as the column.

If the save action is allowed, the row will be saved to the table.

The oldValue is the value of the row before the edit. The newValue is the value of the row after the edit.


List<dynamic>? onRowSave(int index, List<dynamic> oldValue, List<dynamic> newValue) {
//Do some validation on new value and return null if validation fails
if (newValue[0] == null) {
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(
        content: Text("Name cannot be null"),
         ),
    );
  return null;
}
// Do some modification to `newValue` and return `newValue`
newValue[0] = newValue[0].toString().toUpperCase(); // Convert name to uppercase
// Save new data to you list
myData[index] = newValue;
return newValue;
}

Implementation

final List<dynamic>? Function(
    int index, List<dynamic> oldValue, List<dynamic> newValue)? onRowSave;