@@ -178,7 +178,12 @@ class TableHtmlExtension extends HtmlExtension {
178
178
style: context.styledElement! .style,
179
179
child: LayoutBuilder (
180
180
builder: (ctx, constraints) {
181
- final width = MediaQuery .sizeOf (ctx).width;
181
+ double width;
182
+ if (constraints.hasBoundedWidth) {
183
+ width = constraints.maxWidth;
184
+ } else {
185
+ width = MediaQuery .sizeOf (ctx).width - 32 ;
186
+ }
182
187
return _layoutCells (
183
188
context.styledElement as TableElement ,
184
189
context.builtChildrenMap! ,
@@ -217,7 +222,6 @@ List<TableCellElement> _getCellDescendants(List<StyledElement> children) {
217
222
}
218
223
219
224
Widget _layoutCells (TableElement table, Map <StyledElement , InlineSpan > parsedCells, ExtensionContext context, double width) {
220
- width -= 32 ;
221
225
double requiredWidth = 0 ;
222
226
for (final minWidth in table.minWidths) {
223
227
requiredWidth += minWidth;
@@ -259,8 +263,10 @@ Widget _layoutCells(TableElement table, Map<StyledElement, InlineSpan> parsedCel
259
263
...row.children.whereType <TableCellElement >().map ((cell) => cell.rowspan - 1 ),
260
264
];
261
265
// Ignore width set in CSS, there is only one proper layout...
262
- row.children.whereType <TableCellElement >().forEach ((cell)=> cell.style.width = null );
266
+ row.children.whereType <TableCellElement >().forEach ((cell) => cell.style.width = null );
263
267
}
268
+ double borderWidth = rows.first.children.whereType <TableCellElement >().first.style.border? .left.width ?? 0 ;
269
+ double borderAdjustment = borderWidth * columnMax / (columnMax + 1 );
264
270
265
271
// Place the cells in the rows/columns
266
272
final cells = < GridPlacement > [];
@@ -286,15 +292,12 @@ Widget _layoutCells(TableElement table, Map<StyledElement, InlineSpan> parsedCel
286
292
child: CssBoxWidget (
287
293
style: child.style.merge (row.style),
288
294
child: Builder (builder: (context) {
289
- final alignment =
290
- child.style.direction ?? Directionality .of (context);
295
+ final alignment = child.style.direction ?? Directionality .of (context);
291
296
return SizedBox .expand (
292
297
child: Container (
293
298
alignment: _getCellAlignment (child, alignment),
294
299
child: CssBoxWidget .withInlineSpanChildren (
295
- children: [
296
- parsedCells[child] ?? const TextSpan (text: "error" )
297
- ],
300
+ children: [parsedCells[child] ?? const TextSpan (text: "error" )],
298
301
style: Style (),
299
302
),
300
303
),
@@ -315,8 +318,7 @@ Widget _layoutCells(TableElement table, Map<StyledElement, InlineSpan> parsedCel
315
318
}
316
319
317
320
// Create column tracks (insofar there were no colgroups that already defined them)
318
- List <TrackSize > finalColumnSizes = List .generate (cellWidths.length, (index)=> FixedTrackSize (cellWidths[index]));
319
- // finalColumnSizes += List.generate(max(0, columnMax - finalColumnSizes.length), (_) => const IntrinsicContentTrackSize());
321
+ List <TrackSize > finalColumnSizes = List .generate (cellWidths.length, (index) => FixedTrackSize (cellWidths[index] - borderAdjustment));
320
322
321
323
if (finalColumnSizes.isEmpty || rowSizes.isEmpty) {
322
324
// No actual cells to show
@@ -326,7 +328,6 @@ Widget _layoutCells(TableElement table, Map<StyledElement, InlineSpan> parsedCel
326
328
return SingleChildScrollView (
327
329
scrollDirection: Axis .horizontal,
328
330
child: SizedBox (
329
- width: width,
330
331
child: LayoutGrid (
331
332
gridFit: GridFit .loose,
332
333
columnSizes: finalColumnSizes,
0 commit comments