How to style a data table in flutter?
3,136
To achieve this you can have to use Container and Table below.
- In the below code I just cover the table with the Container widget and give the decoration property to have the radius over the border of the table.
- Then just set the table border for inside only so it won't display the outer border which is already covered by the container.
- And finally set the decoration property of the first TableRow(Header) widget.
You can access the sample code from here too.
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1,
),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Table(
// border: TableBorder.all(
// color: Colors.black, width: 1.0, style: BorderStyle.solid),
border: TableBorder.symmetric(
inside: BorderSide(width: 2, color: Colors.black)),
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
columnWidths: {
0: FlexColumnWidth(4),
1: FlexColumnWidth(1),
},
children: [
TableRow(
decoration: BoxDecoration(
color: Colors.blue[100],
border: Border.all(
width: 1,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
),
children: [
Text("Bowler", textScaleFactor: 1),
Text(
"OVR",
textScaleFactor: 1,
textAlign: TextAlign.center,
),
]),
TableRow(children: [
Text(score.bowler.name, textScaleFactor: 1),
Text(
score.bowler.overs.toString(),
textScaleFactor: 1,
textAlign: TextAlign.center,
),
]),
],
),
);
Author by
Jack Maring
Updated on December 18, 2022Comments
-
Jack Maring over 1 year
I was wondering if you could make something like this that I designed using the DataTable widget in flutter?
-
Kiran Maniya about 4 yearsWhat did you try so far?
-
Jack Maring about 4 yearsI actually just made a copy of the DataTable widget into a new file and I've been styling it manually from there.
-
Ahmed Sunny about 4 yearsshare what you have done, css, etc
-