dataRowColor property Null safety

MaterialStateProperty<Color?>? dataRowColor
final

The background color for the data rows.

The effective background color can be made to depend on the MaterialState state, i.e. if the row is selected, pressed, hovered, focused, disabled or enabled. The color is painted as an overlay to the row. To make sure that the row's InkWell is visible (when pressed, hovered and focused), it is recommended to use a translucent background color.

DataTable(
  dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
    if (states.contains(MaterialState.selected))
      return Theme.of(context).colorScheme.primary.withOpacity(0.08);
    return null;  // Use the default value.
  }),
)

See also:

Implementation

final MaterialStateProperty<Color?>? dataRowColor;