Home > Back-end >  Flutter single `DataCell` color
Flutter single `DataCell` color

Time:08-18

I'm trying to do something similar to the Excel/Google Sheets/etc can do and add a background colour to just one single DataCell on my DataTable. I could only find a reference to set an entire DataRow, not just one cell. Does anyone know how?

API reference:

  • DataCell: Cell partially filled with the colour

    Goal:

    Cell fully filled with the colour

    CodePudding user response:

    I've solved this by removing the FittedBox from the widget tree.

    DataCell(
      test
          ? Padding(
              padding: const EdgeInsets.symmetric(vertical: 5),
              child: ColoredBox(
                color: Colors.orange,
                child: Center(
                  child: Text(variable, style: style),
                ),
              ),
            )
          : Center(
              child: Text(variable, style: style),
            ),
    ),
    

    End result:

    DataTable with DataCell completely painted in orange

    PS: The Padding here is just so that the colour stays within the VerticalDivider indents (at the sides).

  • Related