Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions lib/src/layout_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class TableLayoutElement extends LayoutElement {

@override
Widget toWidget(RenderContext context) {
return Container(
decoration: BoxDecoration(
color: style.backgroundColor,
border: style.border,
),
width: style.width,
height: style.height,
child: _layoutCells(context),
);
}

Widget _layoutCells(RenderContext context) {
final rows = <TableRowLayoutElement>[];
List<TrackSize> columnSizes = <TrackSize>[];
for (var child in children) {
Expand All @@ -48,14 +60,14 @@ class TableLayoutElement extends LayoutElement {
colWidth.substring(0, colWidth.length - 1));
return percentageSize != null
? FlexibleTrackSize(percentageSize * 0.01)
: FlexibleTrackSize(1);
: IntrinsicContentTrackSize();
} else if (colWidth != null) {
final fixedPxSize = double.tryParse(colWidth);
return fixedPxSize != null
? FixedTrackSize(fixedPxSize)
: FlexibleTrackSize(1);
: IntrinsicContentTrackSize();
} else {
return FlexibleTrackSize(1);
return IntrinsicContentTrackSize();
Comment on lines +63 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this new flutter_layout_grid parameter correctly size when images are in a table? Curious to know whether this fixes that one issue we were having with small images inside tables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I'm going to remove my comment on your image render proposal since this takes care of that.

}
});
})
Expand Down Expand Up @@ -101,7 +113,8 @@ class TableLayoutElement extends LayoutElement {
),
child: SizedBox.expand(
child: Container(
alignment: child.style.alignment ?? style.alignment ??
alignment: child.style.alignment ??
style.alignment ??
Alignment.centerLeft,
child: StyledText(
textSpan: context.parser.parseTree(context, child),
Expand All @@ -123,29 +136,21 @@ class TableLayoutElement extends LayoutElement {
}

// Create column tracks (insofar there were no colgroups that already defined them)
List<TrackSize> finalColumnSizes = (columnSizes ?? <TrackSize>[]).take(
columnMax).toList();
List<TrackSize> finalColumnSizes =
(columnSizes ?? <TrackSize>[]).take(columnMax).toList();
finalColumnSizes += List.generate(
max(0, columnMax - finalColumnSizes.length),
(_) => FlexibleTrackSize(1));
return Container(
decoration: BoxDecoration(
color: style.backgroundColor,
border: style.border,
),
width: style.width,
height: style.height,
child: LayoutGrid(
gridFit: GridFit.loose,
templateColumnSizes: finalColumnSizes,
templateRowSizes: rowSizes,
children: cells,
),
(_) => IntrinsicContentTrackSize());

return LayoutGrid(
gridFit: GridFit.loose,
templateColumnSizes: finalColumnSizes,
templateRowSizes: rowSizes,
children: cells,
);
}
}


class TableSectionLayoutElement extends LayoutElement {
TableSectionLayoutElement({
String name,
Expand Down Expand Up @@ -185,12 +190,12 @@ class TableCellElement extends StyledElement {
Style style,
dom.Element node,
}) : super(
name: name,
elementId: elementId,
elementClasses: elementClasses,
children: children,
style: style,
node: node) {
name: name,
elementId: elementId,
elementClasses: elementClasses,
children: children,
style: style,
node: node) {
colspan = _parseSpan(this, "colspan");
rowspan = _parseSpan(this, "rowspan");
}
Expand All @@ -201,8 +206,9 @@ class TableCellElement extends StyledElement {
}
}

TableCellElement parseTableCellElement(dom.Element element,
List<StyledElement> children,
TableCellElement parseTableCellElement(
dom.Element element,
List<StyledElement> children,
) {
final cell = TableCellElement(
name: element.localName,
Expand All @@ -228,8 +234,9 @@ class TableStyleElement extends StyledElement {
}) : super(name: name, children: children, style: style, node: node);
}

TableStyleElement parseTableDefinitionElement(dom.Element element,
List<StyledElement> children,
TableStyleElement parseTableDefinitionElement(
dom.Element element,
List<StyledElement> children,
) {
switch (element.localName) {
case "colgroup":
Expand All @@ -244,8 +251,9 @@ TableStyleElement parseTableDefinitionElement(dom.Element element,
}
}

LayoutElement parseLayoutElement(dom.Element element,
List<StyledElement> children,
LayoutElement parseLayoutElement(
dom.Element element,
List<StyledElement> children,
) {
switch (element.localName) {
case "table":
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
css_colors: ^1.0.2

# Plugins for rendering the <table> tag.
flutter_layout_grid: ^0.10.2
flutter_layout_grid: ^0.10.5

# Plugins for rendering the <video> tag.
video_player: ^1.0.1
Expand Down