File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ const htmlData = """
80
80
<tr><td>fData</td><td>fData</td><td>fData</td></tr>
81
81
</tfoot>
82
82
</table>
83
- <h3>Custom Element Support:</h3>
83
+ <h3>Custom Element Support (inline: <bird></bird> and as block) :</h3>
84
84
<flutter></flutter>
85
85
<flutter horizontal></flutter>
86
86
<h3>SVG support:</h3>
@@ -121,7 +121,6 @@ const htmlData = """
121
121
<p>
122
122
<img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
123
123
<a href='https://google.com'><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></a>
124
- <img alt='Alt Text of an intentionally broken image' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30d' />
125
124
</p>
126
125
<h3>Video support:</h3>
127
126
<video controls>
@@ -172,6 +171,9 @@ class _MyHomePageState extends State<MyHomePage> {
172
171
"var" : Style (fontFamily: 'serif' ),
173
172
},
174
173
customRender: {
174
+ "bird" : (RenderContext context, Widget child, attributes, _) {
175
+ return TextSpan (text: "🐦" );
176
+ },
175
177
"flutter" : (RenderContext context, Widget child, attributes, _) {
176
178
return FlutterLogo (
177
179
style: (attributes['horizontal' ] != null )
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import 'package:html/parser.dart' as htmlparser;
15
15
import 'package:webview_flutter/webview_flutter.dart' ;
16
16
17
17
typedef OnTap = void Function (String url);
18
- typedef CustomRender = Widget Function (
18
+ typedef CustomRender = dynamic Function (
19
19
RenderContext context,
20
20
Widget parsedChild,
21
21
Map <String , String > attributes,
@@ -243,7 +243,7 @@ class HtmlParser extends StatelessWidget {
243
243
);
244
244
245
245
if (customRender? .containsKey (tree.name) ?? false ) {
246
- dynamic customRenderForElement = customRender[tree.name].call (
246
+ final render = customRender[tree.name].call (
247
247
newContext,
248
248
ContainerSpan (
249
249
newContext: newContext,
@@ -257,16 +257,18 @@ class HtmlParser extends StatelessWidget {
257
257
tree.attributes,
258
258
tree.element,
259
259
);
260
-
261
- if (customRenderForElement != null ) {
262
- return WidgetSpan (
263
- child: ContainerSpan (
264
- newContext: newContext,
265
- style: tree.style,
266
- shrinkWrap: context.parser.shrinkWrap,
267
- child: customRenderForElement,
268
- ),
269
- );
260
+ if (render != null ) {
261
+ assert (render is InlineSpan || render is Widget );
262
+ return render is InlineSpan
263
+ ? render
264
+ : WidgetSpan (
265
+ child: ContainerSpan (
266
+ newContext: newContext,
267
+ style: tree.style,
268
+ shrinkWrap: context.parser.shrinkWrap,
269
+ child: render,
270
+ ),
271
+ );
270
272
}
271
273
}
272
274
You can’t perform that action at this time.
0 commit comments