Skip to content

Ensure non-negative insets are used for all margins and paddings #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 8, 2021
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
6 changes: 3 additions & 3 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class HtmlParser extends StatelessWidget {
children: [
tree.style.listStylePosition == ListStylePosition.OUTSIDE ?
Padding(
padding: tree.style.padding ?? EdgeInsets.only(left: tree.style.direction != TextDirection.rtl ? 10.0 : 0.0, right: tree.style.direction == TextDirection.rtl ? 10.0 : 0.0),
padding: tree.style.padding?.nonNegative ?? EdgeInsets.only(left: tree.style.direction != TextDirection.rtl ? 10.0 : 0.0, right: tree.style.direction == TextDirection.rtl ? 10.0 : 0.0),
child: newContext.style.markerContent
) : Container(height: 0, width: 0),
Text("\t", textAlign: TextAlign.right, style: TextStyle(fontWeight: FontWeight.w400)),
Expand Down Expand Up @@ -1056,8 +1056,8 @@ class ContainerSpan extends StatelessWidget {
),
height: style.height,
width: style.width,
padding: style.padding,
margin: style.margin?.clamp(EdgeInsets.zero, const EdgeInsets.all(double.infinity)),
padding: style.padding?.nonNegative,
margin: style.margin?.nonNegative,
alignment: shrinkWrap ? null : style.alignment,
child: child ??
StyledText(
Expand Down
7 changes: 4 additions & 3 deletions lib/src/layout_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_html/html_parser.dart';
import 'package:flutter_html/src/anchor.dart';
import 'package:flutter_html/src/html_elements.dart';
import 'package:flutter_html/src/styled_element.dart';
import 'package:flutter_html/src/utils.dart';
import 'package:flutter_html/style.dart';
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
import 'package:html/dom.dart' as dom;
Expand Down Expand Up @@ -33,8 +34,8 @@ class TableLayoutElement extends LayoutElement {
Widget toWidget(RenderContext context) {
return Container(
key: AnchorKey.of(context.parser.key, this),
margin: style.margin,
padding: style.padding,
padding: style.padding?.nonNegative,
margin: style.margin?.nonNegative,
alignment: style.alignment,
decoration: BoxDecoration(
color: style.backgroundColor,
Expand Down Expand Up @@ -122,7 +123,7 @@ class TableLayoutElement extends LayoutElement {
cells.add(GridPlacement(
child: Container(
width: double.infinity,
padding: child.style.padding ?? row.style.padding,
padding: child.style.padding?.nonNegative ?? row.style.padding?.nonNegative,
decoration: BoxDecoration(
color: child.style.backgroundColor ?? row.style.backgroundColor,
border: child.style.border ?? row.style.border,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ extension TextTransformUtil on String? {
return this;
}
}
}

extension ClampedEdgeInsets on EdgeInsetsGeometry {
EdgeInsetsGeometry get nonNegative => this.clamp(EdgeInsets.zero, const EdgeInsets.all(double.infinity));
}