Skip to content

Commit 8c14f9c

Browse files
authored
Replace Codecov badge with SonarCloud's (#1432)
1 parent 227e6c4 commit 8c14f9c

File tree

17 files changed

+97
-62
lines changed

17 files changed

+97
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# HtmlWidget monorepo
22

33
[![Flutter](https://github.com/daohoangson/flutter_widget_from_html/actions/workflows/flutter.yml/badge.svg)](https://github.com/daohoangson/flutter_widget_from_html/actions/workflows/flutter.yml)
4-
[![codecov](https://codecov.io/gh/daohoangson/flutter_widget_from_html/branch/master/graph/badge.svg)](https://codecov.io/gh/daohoangson/flutter_widget_from_html)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=daohoangson_flutter_widget_from_html&metric=coverage)](https://sonarcloud.io/summary/new_code?id=daohoangson_flutter_widget_from_html)
55

66
This repo contains the source code for everything `HtmlWidget`-related.
77

packages/core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Flutter Widget from HTML (core)
22

33
[![Flutter](https://github.com/daohoangson/flutter_widget_from_html/actions/workflows/flutter.yml/badge.svg)](https://github.com/daohoangson/flutter_widget_from_html/actions/workflows/flutter.yml)
4-
[![codecov](https://codecov.io/gh/daohoangson/flutter_widget_from_html/branch/master/graph/badge.svg)](https://codecov.io/gh/daohoangson/flutter_widget_from_html)
4+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=daohoangson_flutter_widget_from_html&metric=coverage)](https://sonarcloud.io/summary/new_code?id=daohoangson_flutter_widget_from_html)
55
[![Pub](https://img.shields.io/pub/v/flutter_widget_from_html_core.svg)](https://pub.dev/packages/flutter_widget_from_html_core)
66

77
Flutter package to render html as widgets that focuses on correctness and extensibility.

packages/core/lib/src/core_helpers.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ Uint8List? bytesFromDataUri(String dataUri) {
189189
final prefix = match[0]!;
190190
final encoding = match[1];
191191
final data = dataUri.substring(prefix.length);
192-
final bytes = encoding == 'base64'
193-
? base64.decode(data)
194-
: encoding == 'utf8'
195-
? Uint8List.fromList(data.codeUnits)
196-
: null;
197192

198-
return bytes?.isNotEmpty == true ? bytes : null;
193+
final Uint8List bytes;
194+
if (encoding == 'base64') {
195+
bytes = base64.decode(data);
196+
} else if (encoding == 'utf8') {
197+
bytes = Uint8List.fromList(data.codeUnits);
198+
} else {
199+
return null;
200+
}
201+
202+
return bytes.isNotEmpty == true ? bytes : null;
199203
}
200204

201205
/// Parses [key] from [map] as an double literal and return its value.

packages/core/lib/src/core_html_widget.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,15 @@ class HtmlWidgetState extends State<HtmlWidget> {
261261
return built;
262262
}
263263

264-
Widget _sliverToBoxAdapterIfNeeded(Widget child) =>
265-
widget.renderMode == RenderMode.sliverList
266-
? child == widget0
267-
? const SliverToBoxAdapter(child: widget0)
268-
: SliverToBoxAdapter(child: child)
269-
: child;
264+
Widget _sliverToBoxAdapterIfNeeded(Widget child) {
265+
if (widget.renderMode != RenderMode.sliverList) {
266+
return child;
267+
}
268+
269+
return child == widget0
270+
? const SliverToBoxAdapter(child: widget0)
271+
: SliverToBoxAdapter(child: child);
272+
}
270273

271274
Widget _wrapper(Widget child) =>
272275
_RootWidget(resolved: _rootProperties, child: child);

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,18 @@ class CssBorderSide {
217217
}
218218

219219
static CssBorderSide? _copyWith(CssBorderSide? base, CssBorderSide? value) {
220-
final copied = base == null || value == none
221-
? value
222-
: value == null
223-
? base
224-
: CssBorderSide(
225-
color: value.color ?? base.color,
226-
style: value.style ?? base.style,
227-
width: value.width ?? base.width,
228-
);
220+
final CssBorderSide? copied;
221+
if (base == null || value == none) {
222+
copied = value;
223+
} else if (value == null) {
224+
copied = base;
225+
} else {
226+
copied = CssBorderSide(
227+
color: value.color ?? base.color,
228+
style: value.style ?? base.style,
229+
width: value.width ?? base.width,
230+
);
231+
}
229232

230233
if (copied?.isNoOp == true) {
231234
return none;

packages/core/lib/src/internal/core_build_tree.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class CoreBuildTree extends BuildTree {
154154
}
155155

156156
@override
157-
void flatten(Flattened _) {
157+
void flatten(Flattened f) {
158158
final scopedBuildOps = _buildOps;
159159
if (scopedBuildOps != null) {
160160
for (final op in scopedBuildOps) {

packages/core/lib/src/internal/margin_vertical.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:flutter/widgets.dart';
24

35
import '../core_data.dart';
@@ -65,8 +67,9 @@ extension SkipBuildHeightPlaceholder on BuildContext {
6567
/// This type of placeholder has special merging logic so they need
6668
/// to be preserved during column contents traversal.
6769
set skipBuildHeightPlaceholder(bool newValue) {
68-
final v = _skipBuildOrZero;
69-
_skipBuild[this] = newValue ? (v + 1) : (v > 0 ? v - 1 : 0);
70+
final delta = newValue ? 1 : -1;
71+
final newCounter = _skipBuildOrZero + delta;
72+
_skipBuild[this] = max(0, newCounter);
7073
}
7174

7275
int get _skipBuildOrZero => _skipBuild[this] ?? 0;

packages/core/lib/src/internal/ops/tag_li.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,23 @@ class TagLi {
9191
static StylesMap _defaultStyles(dom.Element element) {
9292
final attrs = element.attributes;
9393
final depth = element.elementDepth;
94-
final listStyleType = element.localName == kTagOrderedList
95-
? (_listStyleTypeFromAttributeType(attrs[kAttributeLiType] ?? '') ??
96-
kCssListStyleTypeDecimal)
97-
: depth == 0
98-
? kCssListStyleTypeDisc
99-
: depth == 1
100-
? kCssListStyleTypeCircle
101-
: kCssListStyleTypeSquare;
94+
95+
final String listStyleType;
96+
if (element.localName == kTagOrderedList) {
97+
listStyleType =
98+
_listStyleTypeFromAttributeType(attrs[kAttributeLiType] ?? '') ??
99+
kCssListStyleTypeDecimal;
100+
} else {
101+
switch (depth) {
102+
case 0:
103+
listStyleType = kCssListStyleTypeDisc;
104+
case 1:
105+
listStyleType = kCssListStyleTypeCircle;
106+
default:
107+
listStyleType = kCssListStyleTypeSquare;
108+
}
109+
}
110+
102111
return {
103112
kCssDisplay: kCssDisplayBlock,
104113
kCssListStyleType: listStyleType,

packages/core/lib/src/internal/ops/tag_table.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,10 @@ class TagTable {
156156
}
157157

158158
final columnSpan = cell.columnSpan > 0 ? cell.columnSpan : 1;
159+
final rowSpanDefault = cell.rowSpan == 0 ? group.rows.length : 1;
159160
final rowSpan = min(
160161
rowSpanMax,
161-
cell.rowSpan > 0
162-
? cell.rowSpan
163-
: cell.rowSpan == 0
164-
? group.rows.length
165-
: 1,
162+
cell.rowSpan > 0 ? cell.rowSpan : rowSpanDefault,
166163
);
167164

168165
final builderIndex = data.builders.length;
@@ -310,11 +307,15 @@ class TagTable {
310307
case kCssDisplayTableHeaderGroup:
311308
case kCssDisplayTableRowGroup:
312309
case kCssDisplayTableFooterGroup:
313-
final group = which == kCssDisplayTableHeaderGroup
314-
? data.header
315-
: which == kCssDisplayTableRowGroup
316-
? data.newBody()
317-
: data.footer;
310+
final _TagTableRowGroup group;
311+
switch (which) {
312+
case kCssDisplayTableHeaderGroup:
313+
group = data.header;
314+
case kCssDisplayTableRowGroup:
315+
group = data.newBody();
316+
default:
317+
group = data.footer;
318+
}
318319
subTree.register(group._groupOp);
319320
case kCssDisplayTableRow:
320321
subTree.register(data.newBody().newRow()._rowOp);

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,31 @@ CssColor? tryParseColor(css.Expression? expression) {
1616
final params = expression.params;
1717
if (params.length >= 3) {
1818
final param0 = params[0];
19-
final h = param0 is css.NumberTerm
20-
? _parseColorHue(param0.number)
21-
: param0 is css.AngleTerm
22-
? _parseColorHue(param0.angle, param0.unit)
23-
: null;
19+
final double? h;
20+
if (param0 is css.NumberTerm) {
21+
h = _parseColorHue(param0.number);
22+
} else if (param0 is css.AngleTerm) {
23+
h = _parseColorHue(param0.angle, param0.unit);
24+
} else {
25+
h = null;
26+
}
27+
2428
final param1 = params[1];
25-
final s = param1 is css.PercentageTerm
26-
? param1.valueAsDouble.clamp(0.0, 1.0)
27-
: null;
29+
final double? s;
30+
if (param1 is css.PercentageTerm) {
31+
s = param1.valueAsDouble.clamp(0.0, 1.0);
32+
} else {
33+
s = null;
34+
}
35+
2836
final param2 = params[2];
29-
final l = param2 is css.PercentageTerm
30-
? param2.valueAsDouble.clamp(0.0, 1.0)
31-
: null;
37+
final double? l;
38+
if (param2 is css.PercentageTerm) {
39+
l = param2.valueAsDouble.clamp(0.0, 1.0);
40+
} else {
41+
l = null;
42+
}
43+
3244
final hslA = params.length >= 4 ? _parseColorAlpha(params[3]) : 1.0;
3345
if (h != null && s != null && l != null && hslA != null) {
3446
final hslValue = HSLColor.fromAHSL(hslA, h, s, l).toColor();

0 commit comments

Comments
 (0)