Skip to content

Commit 1870d24

Browse files
authored
Fix border 0 is still being rendered. (#1045)
Also: * [core] v0.10.6 * [enhanced] v0.10.6
1 parent b700fc5 commit 1870d24

File tree

9 files changed

+88
-40
lines changed

9 files changed

+88
-40
lines changed

packages/core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.6
2+
3+
- Fix border 0 is still being rendered (#1045)
4+
15
## 0.10.5
26

37
- Replace the deprecated `DecoderCallback` in tests (#1014)

packages/core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add this to your app's `pubspec.yaml` file:
2020

2121
```yaml
2222
dependencies:
23-
flutter_widget_from_html_core: ^0.10.5
23+
flutter_widget_from_html_core: ^0.10.6
2424
```
2525
2626
## Usage

packages/core/lib/src/data/css.dart

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class CssBorder {
4242

4343
/// Returns `true` if all sides are unset, all radius are zero.
4444
bool get isNoOp =>
45-
(_all == null || _all == CssBorderSide.none) &&
46-
(_bottom == null || _bottom == CssBorderSide.none) &&
47-
(_inlineEnd == null || _inlineEnd == CssBorderSide.none) &&
48-
(_inlineStart == null || _inlineStart == CssBorderSide.none) &&
49-
(_left == null || _left == CssBorderSide.none) &&
50-
(_right == null || _right == CssBorderSide.none) &&
51-
(_top == null || _top == CssBorderSide.none) &&
45+
(_all?.isNoOp != false) &&
46+
(_bottom?.isNoOp != false) &&
47+
(_inlineEnd?.isNoOp != false) &&
48+
(_inlineStart?.isNoOp != false) &&
49+
(_left?.isNoOp != false) &&
50+
(_right?.isNoOp != false) &&
51+
(_top?.isNoOp != false) &&
5252
radiusBottomLeft == CssRadius.zero &&
5353
radiusBottomRight == CssRadius.zero &&
5454
radiusTopLeft == CssRadius.zero &&
@@ -189,27 +189,51 @@ class CssBorderSide {
189189
/// A border that is not rendered.
190190
static const none = CssBorderSide();
191191

192-
BorderSide? _getValue(TextStyleHtml tsh) => identical(this, none)
193-
? null
194-
: BorderSide(
195-
color: color ?? tsh.style.color ?? const BorderSide().color,
196-
// TODO: add proper support for other border styles
197-
style: style != null ? BorderStyle.solid : BorderStyle.none,
198-
// TODO: look for official document regarding this default value
199-
// WebKit & Blink seem to follow the same (hidden?) specs
200-
width: width?.getValue(tsh) ?? 1.0,
201-
);
192+
/// Returns `true` if either [style] or [width] is invalid.
193+
///
194+
/// Border will use the default text color so [color] is not required.
195+
bool get isNoOp => style == null || width?.isPositive != true;
196+
197+
BorderSide? _getValue(TextStyleHtml tsh) {
198+
if (identical(this, none)) {
199+
return null;
200+
}
202201

203-
static CssBorderSide? _copyWith(CssBorderSide? base, CssBorderSide? value) =>
204-
base == null || value == none
205-
? value
206-
: value == null
207-
? base
208-
: CssBorderSide(
209-
color: value.color ?? base.color,
210-
style: value.style ?? base.style,
211-
width: value.width ?? base.width,
212-
);
202+
final scopedColor = color ?? tsh.style.color;
203+
if (scopedColor == null) {
204+
return null;
205+
}
206+
207+
final scopedWidth = width?.getValue(tsh);
208+
if (scopedWidth == null) {
209+
return null;
210+
}
211+
212+
return BorderSide(
213+
color: scopedColor,
214+
// TODO: add proper support for other border styles
215+
style: style != null ? BorderStyle.solid : BorderStyle.none,
216+
width: scopedWidth,
217+
);
218+
}
219+
220+
static CssBorderSide? _copyWith(CssBorderSide? base, CssBorderSide? value) {
221+
final copied = base == null || value == none
222+
? value
223+
: value == null
224+
? base
225+
: CssBorderSide(
226+
color: value.color ?? base.color,
227+
style: value.style ?? base.style,
228+
width: value.width ?? base.width,
229+
);
230+
231+
if (copied?.isNoOp == true) {
232+
return none;
233+
}
234+
235+
return copied;
236+
}
213237
}
214238

215239
/// A length measurement.

packages/core/lib/src/internal/parser/border.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ part of '../core_parser.dart';
22

33
const kCssBorder = 'border';
44
const kCssBorderInherit = 'inherit';
5+
const kCssBorderNone = 'none';
56

67
const kCssBorderRadius = 'border-radius';
78
const kCssBorderRadiusSuffix = 'radius';
@@ -42,9 +43,20 @@ CssBorder _tryParseBorderSide(CssBorder border, css.Declaration style) {
4243
}
4344

4445
TextDecorationStyle? borderStyle;
45-
CssLength? width;
4646
Color? color;
47+
// TODO: look for official document regarding this default value
48+
// WebKit & Blink seem to follow the same (hidden?) specs
49+
var width = const CssLength(1);
4750
for (final expression in style.values) {
51+
final value =
52+
expression is css.LiteralTerm ? expression.valueAsString : null;
53+
if (value == kCssBorderNone) {
54+
borderStyle = null;
55+
color = null;
56+
width = CssLength.zero;
57+
break;
58+
}
59+
4860
final parsedStyle = tryParseTextDecorationStyle(expression);
4961
if (parsedStyle != null) {
5062
borderStyle = parsedStyle;
@@ -64,13 +76,11 @@ CssBorder _tryParseBorderSide(CssBorder border, css.Declaration style) {
6476
}
6577
}
6678

67-
final borderSide = borderStyle == null
68-
? CssBorderSide.none
69-
: CssBorderSide(
70-
color: color,
71-
style: borderStyle,
72-
width: width,
73-
);
79+
final borderSide = CssBorderSide(
80+
color: color,
81+
style: borderStyle,
82+
width: width,
83+
);
7484

7585
if (suffix.isEmpty) {
7686
return border.copyWith(all: borderSide);

packages/core/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: flutter_widget_from_html_core
2-
version: 0.10.5
2+
version: 0.10.6
33
description: Flutter package to render html as widgets that focuses on correctness and extensibility.
44
homepage: https://github.com/daohoangson/flutter_widget_from_html/tree/master/packages/core
55

packages/core/test/style_border_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,12 @@ void main() {
12381238
expect(explained, equals('[RichText:(:Foo)]'));
12391239
});
12401240

1241+
testWidgets('#1044: border zero', (WidgetTester tester) async {
1242+
const html = '<span style="border: 0 solid red">Foo</span>';
1243+
final explained = await explain(tester, html);
1244+
expect(explained, equals('[RichText:(:Foo)]'));
1245+
});
1246+
12411247
testWidgets('negative value', (WidgetTester tester) async {
12421248
const html = '<span style="border: -1px">Foo</span>';
12431249
final explained = await explain(tester, html);

packages/enhanced/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.10.6
2+
3+
- Fix border 0 is still being rendered (#1045)
4+
15
## 0.10.5+3
26

37
- Add support for fullscreen webview in Android (#1022)

packages/enhanced/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Add this to your app's `pubspec.yaml` file:
2727

2828
```yaml
2929
dependencies:
30-
flutter_widget_from_html: ^0.10.5
30+
flutter_widget_from_html: ^0.10.6
3131
```
3232
3333
### Platform specific configuration

packages/enhanced/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: flutter_widget_from_html
2-
version: 0.10.5+3
2+
version: 0.10.6
33
description: Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
44
homepage: https://github.com/daohoangson/flutter_widget_from_html
55

@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
flutter_widget_from_html_core: ^0.10.5
13+
flutter_widget_from_html_core: ^0.10.6
1414
fwfh_cached_network_image: ^0.7.0+7
1515
fwfh_chewie: ^0.7.1+4
1616
fwfh_just_audio: ^0.9.0+3

0 commit comments

Comments
 (0)