dataRowColor property
final
The background color for the data rows.
The effective background color can be made to depend on the WidgetState 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.
If DataRow.onSelectChanged or DataRow.onLongPress is null, the row's InkWell will be disabled.
If null, DataTableThemeData.dataRowColor is used. By default, the background color is transparent unless selected. Selected rows have a grey translucent color. To set a different color for individual rows, see DataRow.color.
DataTable(
dataRowColor: WidgetStateProperty.resolveWith<Color?>((Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return Theme.of(context).colorScheme.primary.withOpacity(0.08);
}
return null; // Use the default value.
}),
columns: _columns,
rows: _rows,
)
See also:
- The Material Design specification for overlay colors and how they match a component's state: material.io/design/interaction/states.html#anatomy.
Implementation
final MaterialStateProperty<Color?>? dataRowColor;