Skip to content

Commit 48bbeb9

Browse files
committed
improve table style
1 parent ba8301c commit 48bbeb9

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

example/lib/main.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ const htmlData = """
4343
</p>
4444
<table>
4545
<colgroup>
46-
<col width="70%" />
46+
<col width="50%" />
47+
<col width="25%" />
48+
<col width="25%" />
4749
</colgroup>
4850
<thead>
4951
<tr><th>One</th><th>Two</th><th>Three</th></tr>
5052
</thead>
5153
<tbody>
52-
<tr><td><b>Data</b></td><td>Data</td><td>Data</td></tr>
5354
<tr>
5455
<td>Data</td><td>Data</td><td>Data</td>
5556
</tr>
@@ -124,6 +125,20 @@ class _MyHomePageState extends State<MyHomePage> {
124125
"#whitespace": Style(
125126
backgroundColor: Colors.purple,
126127
),
128+
"table": Style(
129+
backgroundColor: Color.fromARGB(0x50, 0xee, 0xee, 0xee)
130+
),
131+
"tr": Style(
132+
border: Border(bottom: BorderSide(color: Colors.grey))
133+
),
134+
"th": Style(
135+
padding: EdgeInsets.all(6),
136+
backgroundColor: Colors.grey
137+
),
138+
"td": Style(
139+
padding: EdgeInsets.all(6),
140+
backgroundColor: Colors.transparent
141+
)
127142
},
128143
customRender: {
129144
"flutter": (RenderContext context, Widget child, attributes) {

lib/src/layout_element.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ class TableLayoutElement extends LayoutElement {
4242
});
4343
}).expand((i) => i).toList().asMap();
4444

45-
return Table(
46-
columnWidths: colWidths,
47-
children: children
48-
.map((c) {
45+
return Container(
46+
decoration: BoxDecoration(
47+
color: style.backgroundColor
48+
),
49+
child: Table(
50+
columnWidths: colWidths,
51+
children: children.map((c) {
4952
if (c is TableSectionLayoutElement) {
5053
return c.toTableRows(context);
5154
}
5255
return null;
5356
})
54-
.where((t) {
57+
.where((t) {
5558
return t != null;
5659
})
5760
.toList()
5861
.expand((i) => i)
5962
.toList(),
60-
);
63+
));
6164
}
6265
}
6366

@@ -98,9 +101,18 @@ class TableRowLayoutElement extends LayoutElement {
98101

99102
TableRow toTableRow(RenderContext context) {
100103
return TableRow(
104+
decoration: BoxDecoration(
105+
border: style.border,
106+
),
101107
children: children.map((c) {
102108
if (c is StyledElement && c.name == 'td' || c.name == 'th') {
103-
return RichText(text: context.parser.parseTree(context, c));
109+
return TableCell(
110+
child: Container(
111+
padding: c.style.padding,
112+
decoration: BoxDecoration(
113+
color: c.style.backgroundColor
114+
),
115+
child: RichText(text: context.parser.parseTree(context, c))));
104116
}
105117
return null;
106118
}).where((c) => c != null).toList());

0 commit comments

Comments
 (0)