File tree Expand file tree Collapse file tree 5 files changed +39
-3
lines changed Expand file tree Collapse file tree 5 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -21,5 +21,6 @@ This changelog highlights changes as we work to implement version 1.0.0.
21
21
* The default text style now matches the app's Material ` TextTheme.body1 ` (Fixes [ #18 ] ( https://github.com/Sub6Resources/flutter_html/issues/18 ) ).
22
22
* Fixed quite a few issues with ` img `
23
23
* Added a fancy new ` style ` attribute (this should be used in place of the deprecated styling parameters).
24
+ * Added an even fancier new ` css ` attribute that takes a CSS string and applies those styles to your widgets.
24
25
25
26
Original file line number Diff line number Diff line change 1
1
# flutter_html
2
2
[ ![ pub package] ( https://img.shields.io/pub/v/flutter_html.svg )] ( https://pub.dev/packages/flutter_html )
3
+ [ ![ codecov] ( https://codecov.io/gh/Sub6Resources/flutter_html/branch/master/graph/badge.svg )] ( https://codecov.io/gh/Sub6Resources/flutter_html )
3
4
[ ![ CircleCI] ( https://circleci.com/gh/Sub6Resources/flutter_html.svg?style=svg )] ( https://circleci.com/gh/Sub6Resources/flutter_html )
4
5
5
6
A Flutter widget for rendering html and css as Flutter widgets.
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class HtmlParser extends StatelessWidget {
36
36
cleanedTree,
37
37
);
38
38
39
- return Text . rich ( parsedTree);
39
+ return RichText (text : parsedTree);
40
40
}
41
41
42
42
/// [parseHTML] converts a string to a DOM document using the dart `html` library.
@@ -91,8 +91,9 @@ class HtmlParser extends StatelessWidget {
91
91
92
92
static StyledElement applyCSS (StyledElement tree, css.StyleSheet sheet) {
93
93
sheet.topLevels.forEach ((treeNode) {
94
- if (treeNode is css.RuleSet ) {
95
- print (treeNode.selectorGroup.selectors.first.simpleSelectorSequences.first.simpleSelector.name);
94
+ if (treeNode is css.RuleSet ) {
95
+ print (treeNode.selectorGroup.selectors.first.simpleSelectorSequences
96
+ .first.simpleSelector.name);
96
97
}
97
98
});
98
99
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
2
2
import 'package:flutter_html/block_element.dart' ;
3
3
4
4
class Style {
5
+ Display display;
5
6
TextStyle textStyle;
6
7
bool preserveWhitespace;
7
8
int baselineOffset;
@@ -11,6 +12,7 @@ class Style {
11
12
Block block;
12
13
13
14
Style ({
15
+ this .display,
14
16
this .textStyle,
15
17
this .preserveWhitespace,
16
18
this .baselineOffset,
@@ -32,6 +34,7 @@ class Style {
32
34
Block mergedBlock = block? .merge (other.block);
33
35
34
36
return copyWith (
37
+ display: other.display,
35
38
textStyle: mergedTextStyle,
36
39
preserveWhitespace: other.preserveWhitespace,
37
40
baselineOffset: other.baselineOffset,
@@ -43,6 +46,7 @@ class Style {
43
46
}
44
47
45
48
Style copyWith ({
49
+ Display display,
46
50
TextStyle textStyle,
47
51
bool preserveWhitespace,
48
52
int baselineOffset,
@@ -52,6 +56,7 @@ class Style {
52
56
Block block,
53
57
}) {
54
58
return Style (
59
+ display: display ?? this .display,
55
60
textStyle: textStyle ?? this .textStyle,
56
61
preserveWhitespace: preserveWhitespace ?? this .preserveWhitespace,
57
62
baselineOffset: baselineOffset ?? this .baselineOffset,
@@ -62,3 +67,9 @@ class Style {
62
67
);
63
68
}
64
69
}
70
+
71
+ enum Display {
72
+ BLOCK ,
73
+ INLINE ,
74
+ INLINE_BLOCK ,
75
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_html/html_elements.dart' ;
3
3
import 'package:flutter_html/html_parser.dart' ;
4
+ import 'package:flutter_html/style.dart' ;
4
5
import 'package:flutter_test/flutter_test.dart' ;
5
6
import 'package:flutter_html/flutter_html.dart' ;
6
7
@@ -90,4 +91,25 @@ void testNewParser() {
90
91
expect (audioContentElement.src, hasLength (2 ), reason: "Not enough sources..." );
91
92
}
92
93
});
94
+
95
+ test ("Test style merging" , () {
96
+ Style style1 = Style (
97
+ display: Display .BLOCK ,
98
+ textStyle: TextStyle (fontWeight: FontWeight .bold),
99
+ );
100
+
101
+ Style style2 = Style (
102
+ before: "* " ,
103
+ textDirection: TextDirection .rtl,
104
+ textStyle: TextStyle (fontStyle: FontStyle .italic),
105
+ );
106
+
107
+ Style finalStyle = style1.merge (style2);
108
+
109
+ expect (finalStyle.display, equals (Display .BLOCK ));
110
+ expect (finalStyle.before, equals ("* " ));
111
+ expect (finalStyle.textDirection, equals (TextDirection .rtl));
112
+ expect (finalStyle.textStyle.fontStyle, equals (FontStyle .italic));
113
+ expect (finalStyle.textStyle.fontWeight, equals (FontWeight .bold));
114
+ });
93
115
}
You can’t perform that action at this time.
0 commit comments