@@ -32,11 +32,7 @@ class LinkTextSpan extends TextSpan {
3232 final String url;
3333
3434 LinkTextSpan (
35- {TextStyle style,
36- this .url,
37- String text,
38- OnLinkTap onLinkTap,
39- List <TextSpan > children})
35+ {TextStyle style, this .url, String text, OnLinkTap onLinkTap, List <TextSpan > children})
4036 : super (
4137 style: style,
4238 text: text,
@@ -80,11 +76,7 @@ class BlockText extends StatelessWidget {
8076 final Decoration decoration;
8177
8278 BlockText (
83- {@required this .child,
84- this .padding,
85- this .margin,
86- this .leadingChar = '' ,
87- this .decoration});
79+ {@required this .child, this .padding, this .margin, this .leadingChar = '' , this .decoration});
8880
8981 @override
9082 Widget build (BuildContext context) {
@@ -255,8 +247,7 @@ class HtmlRichTextParser extends StatelessWidget {
255247 bool _hasBlockChild (dom.Node node, {bool ignoreSelf = true }) {
256248 bool retval = false ;
257249 if (node is dom.Element ) {
258- if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf)
259- return true ;
250+ if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf) return true ;
260251 node.nodes.forEach ((dom.Node node) {
261252 if (_hasBlockChild (node, ignoreSelf: false )) retval = true ;
262253 });
@@ -291,8 +282,7 @@ class HtmlRichTextParser extends StatelessWidget {
291282 if (w is BlockText ) {
292283 if (w.child.text == null ) return ;
293284 if ((w.child.text.text == null || w.child.text.text.isEmpty) &&
294- (w.child.text.children == null || w.child.text.children.isEmpty))
295- return ;
285+ (w.child.text.children == null || w.child.text.children.isEmpty)) return ;
296286 } else if (w is LinkBlock ) {
297287 if (w.children.isEmpty) return ;
298288 } else if (w is LinkTextSpan ) {
@@ -319,8 +309,7 @@ class HtmlRichTextParser extends StatelessWidget {
319309 // function can add child nodes to the parent if it should
320310 //
321311 // each iteration creates a new parseContext as a copy of the previous one if it needs to
322- void _parseNode (
323- dom.Node node, ParseContext parseContext, BuildContext buildContext) {
312+ void _parseNode (dom.Node node, ParseContext parseContext, BuildContext buildContext) {
324313 // TEXT ONLY NODES
325314 // a text only node is a child of a tag with no inner html
326315 if (node is dom.Text ) {
@@ -359,18 +348,15 @@ class HtmlRichTextParser extends StatelessWidget {
359348 // debugPrint("Plain Text Node: '$finalText'");
360349
361350 // create a span by default
362- TextSpan span = TextSpan (
363- text: finalText,
364- children: < TextSpan > [],
365- style: parseContext.childStyle);
351+ TextSpan span =
352+ TextSpan (text: finalText, children: < TextSpan > [], style: parseContext.childStyle);
366353
367354 // in this class, a ParentElement must be a BlockText, LinkTextSpan, Row, Column, TextSpan
368355
369356 // the parseContext might actually be a block level style element, so we
370357 // need to honor the indent and styling specified by that block style.
371358 // e.g. ol, ul, blockquote
372- bool treatLikeBlock =
373- ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
359+ bool treatLikeBlock = ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
374360
375361 // if there is no parentElement, contain the span in a BlockText
376362 if (parseContext.parentElement == null ) {
@@ -381,18 +367,15 @@ class HtmlRichTextParser extends StatelessWidget {
381367 Decoration decoration;
382368 if (parseContext.blockType == 'blockquote' ) {
383369 decoration = BoxDecoration (
384- border:
385- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
370+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
386371 );
387372 parseContext.childStyle = parseContext.childStyle.merge (TextStyle (
388373 fontStyle: FontStyle .italic,
389374 ));
390375 }
391376 BlockText blockText = BlockText (
392- margin: EdgeInsets .only (
393- top: 8.0 ,
394- bottom: 8.0 ,
395- left: parseContext.indentLevel * indentSize),
377+ margin:
378+ EdgeInsets .only (top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
396379 padding: EdgeInsets .all (2.0 ),
397380 decoration: decoration,
398381 child: RichText (
@@ -402,8 +385,7 @@ class HtmlRichTextParser extends StatelessWidget {
402385 );
403386 parseContext.rootWidgetList.add (blockText);
404387 } else {
405- parseContext.rootWidgetList
406- .add (BlockText (child: RichText (text: span)));
388+ parseContext.rootWidgetList.add (BlockText (child: RichText (text: span)));
407389 }
408390
409391 // this allows future items to be added as children of this item
@@ -413,8 +395,7 @@ class HtmlRichTextParser extends StatelessWidget {
413395 } else if (parseContext.parentElement is LinkTextSpan ) {
414396 // add this node to the parent as another LinkTextSpan
415397 parseContext.parentElement.children.add (LinkTextSpan (
416- style:
417- parseContext.parentElement.style.merge (parseContext.childStyle),
398+ style: parseContext.parentElement.style.merge (parseContext.childStyle),
418399 url: parseContext.parentElement.url,
419400 text: finalText,
420401 onLinkTap: onLinkTap,
@@ -447,21 +428,18 @@ class HtmlRichTextParser extends StatelessWidget {
447428 //"b","i","em","strong","code","u","small","abbr","acronym"
448429 case "b" :
449430 case "strong" :
450- childStyle =
451- childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
431+ childStyle = childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
452432 break ;
453433 case "i" :
454434 case "address" :
455435 case "em" :
456- childStyle =
457- childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
436+ childStyle = childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
458437 break ;
459438 case "code" :
460439 childStyle = childStyle.merge (TextStyle (fontFamily: 'monospace' ));
461440 break ;
462441 case "u" :
463- childStyle = childStyle
464- .merge (TextStyle (decoration: TextDecoration .underline));
442+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .underline));
465443 break ;
466444 case "abbr" :
467445 case "acronym" :
@@ -518,8 +496,7 @@ class HtmlRichTextParser extends StatelessWidget {
518496 if (_hasBlockChild (node)) {
519497 LinkBlock linkContainer = LinkBlock (
520498 url: url,
521- margin: EdgeInsets .only (
522- left: parseContext.indentLevel * indentSize),
499+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize),
523500 onLinkTap: onLinkTap,
524501 children: < Widget > [],
525502 );
@@ -538,8 +515,7 @@ class HtmlRichTextParser extends StatelessWidget {
538515 } else {
539516 // start a new block element for this link and its text
540517 BlockText blockElement = BlockText (
541- margin: EdgeInsets .only (
542- left: parseContext.indentLevel * indentSize, top: 10.0 ),
518+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 10.0 ),
543519 child: RichText (text: span),
544520 );
545521 parseContext.rootWidgetList.add (blockElement);
@@ -551,10 +527,8 @@ class HtmlRichTextParser extends StatelessWidget {
551527 break ;
552528
553529 case "br" :
554- if (parseContext.parentElement != null &&
555- parseContext.parentElement is TextSpan ) {
556- parseContext.parentElement.children
557- .add (TextSpan (text: '\n ' , children: []));
530+ if (parseContext.parentElement != null && parseContext.parentElement is TextSpan ) {
531+ parseContext.parentElement.children.add (TextSpan (text: '\n ' , children: []));
558532 }
559533 break ;
560534
@@ -566,8 +540,7 @@ class HtmlRichTextParser extends StatelessWidget {
566540 children: < Widget > [],
567541 );
568542 nextContext.rootWidgetList.add (Container (
569- margin: EdgeInsets .symmetric (vertical: 12.0 ),
570- child: nextContext.parentElement));
543+ margin: EdgeInsets .symmetric (vertical: 12.0 ), child: nextContext.parentElement));
571544 break ;
572545
573546 // we don't handle tbody, thead, or tfoot elements separately for now
@@ -583,11 +556,8 @@ class HtmlRichTextParser extends StatelessWidget {
583556 colspan = int .tryParse (node.attributes['colspan' ]);
584557 }
585558 nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
586- fontWeight: (node.localName == 'th' )
587- ? FontWeight .bold
588- : FontWeight .normal));
589- RichText text =
590- RichText (text: TextSpan (text: '' , children: < TextSpan > []));
559+ fontWeight: (node.localName == 'th' ) ? FontWeight .bold : FontWeight .normal));
560+ RichText text = RichText (text: TextSpan (text: '' , children: < TextSpan > []));
591561 Expanded cell = Expanded (
592562 flex: colspan,
593563 child: Container (padding: EdgeInsets .all (1.0 ), child: text),
@@ -642,8 +612,7 @@ class HtmlRichTextParser extends StatelessWidget {
642612
643613 switch (node.localName) {
644614 case "hr" :
645- parseContext.rootWidgetList
646- .add (Divider (height: 1.0 , color: Colors .black38));
615+ parseContext.rootWidgetList.add (Divider (height: 1.0 , color: Colors .black38));
647616 break ;
648617 case "img" :
649618 if (node.attributes['src' ] != null ) {
@@ -666,7 +635,6 @@ class HtmlRichTextParser extends StatelessWidget {
666635 scale: imageProperties? .scale ?? 1.0 ,
667636 matchTextDirection: imageProperties? .matchTextDirection ?? false ,
668637 centerSlice: imageProperties? .centerSlice,
669- gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
670638 filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
671639 alignment: imageProperties? .alignment ?? Alignment .center,
672640 colorBlendMode: imageProperties? .colorBlendMode,
@@ -692,7 +660,6 @@ class HtmlRichTextParser extends StatelessWidget {
692660 scale: imageProperties? .scale ?? 1.0 ,
693661 matchTextDirection: imageProperties? .matchTextDirection ?? false ,
694662 centerSlice: imageProperties? .centerSlice,
695- gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
696663 filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
697664 alignment: imageProperties? .alignment ?? Alignment .center,
698665 colorBlendMode: imageProperties? .colorBlendMode,
@@ -728,8 +695,7 @@ class HtmlRichTextParser extends StatelessWidget {
728695 leadingChar = parseContext.listCount.toString () + '.' ;
729696 }
730697 BlockText blockText = BlockText (
731- margin: EdgeInsets .only (
732- left: parseContext.indentLevel * indentSize, top: 3.0 ),
698+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 3.0 ),
733699 child: RichText (
734700 text: TextSpan (
735701 text: '' ,
@@ -790,8 +756,7 @@ class HtmlRichTextParser extends StatelessWidget {
790756 Decoration decoration;
791757 if (parseContext.blockType == 'blockquote' ) {
792758 decoration = BoxDecoration (
793- border:
794- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
759+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
795760 );
796761 nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
797762 fontStyle: FontStyle .italic,
@@ -800,9 +765,7 @@ class HtmlRichTextParser extends StatelessWidget {
800765 BlockText blockText = BlockText (
801766 margin: _customEdgeInsets ??
802767 EdgeInsets .only (
803- top: 8.0 ,
804- bottom: 8.0 ,
805- left: parseContext.indentLevel * indentSize),
768+ top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
806769 padding: EdgeInsets .all (2.0 ),
807770 decoration: decoration,
808771 child: RichText (
@@ -1012,8 +975,7 @@ class HtmlOldParser extends StatelessWidget {
1012975
1013976 Widget _parseNode (dom.Node node) {
1014977 if (customRender != null ) {
1015- final Widget customWidget =
1016- customRender (node, _parseNodeList (node.nodes));
978+ final Widget customWidget = customRender (node, _parseNodeList (node.nodes));
1017979 if (customWidget != null ) {
1018980 return customWidget;
1019981 }
@@ -1103,9 +1065,8 @@ class HtmlOldParser extends StatelessWidget {
11031065 child: Wrap (
11041066 children: _parseNodeList (node.nodes),
11051067 ),
1106- textDirection: node.attributes["dir" ] == "rtl"
1107- ? TextDirection .rtl
1108- : TextDirection .ltr,
1068+ textDirection:
1069+ node.attributes["dir" ] == "rtl" ? TextDirection .rtl : TextDirection .ltr,
11091070 );
11101071 }
11111072 //Direction attribute is required, just render the text normally now.
@@ -1123,8 +1084,7 @@ class HtmlOldParser extends StatelessWidget {
11231084 );
11241085 case "blockquote" :
11251086 return Padding (
1126- padding:
1127- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1087+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
11281088 child: Container (
11291089 width: width,
11301090 child: Wrap (
@@ -1247,8 +1207,7 @@ class HtmlOldParser extends StatelessWidget {
12471207 );
12481208 case "figure" :
12491209 return Padding (
1250- padding:
1251- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1210+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
12521211 child: Column (
12531212 children: _parseNodeList (node.nodes),
12541213 crossAxisAlignment: CrossAxisAlignment .center,
@@ -1378,13 +1337,12 @@ class HtmlOldParser extends StatelessWidget {
13781337 if (node.attributes['src' ].startsWith ("data:image" ) &&
13791338 node.attributes['src' ].contains ("base64," )) {
13801339 precacheImage (
1381- MemoryImage (base64.decode (
1382- node.attributes['src' ].split ("base64," )[1 ].trim ())),
1340+ MemoryImage (base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ())),
13831341 context,
13841342 onError: onImageError,
13851343 );
1386- return Image .memory (base64. decode (
1387- node.attributes['src' ].split ("base64," )[1 ].trim ()));
1344+ return Image .memory (
1345+ base64. decode ( node.attributes['src' ].split ("base64," )[1 ].trim ()));
13881346 }
13891347 precacheImage (
13901348 NetworkImage (node.attributes['src' ]),
@@ -1396,8 +1354,7 @@ class HtmlOldParser extends StatelessWidget {
13961354 //Temp fix for https://github.com/flutter/flutter/issues/736
13971355 if (node.attributes['alt' ].endsWith (" " )) {
13981356 return Container (
1399- padding: EdgeInsets .only (right: 2.0 ),
1400- child: Text (node.attributes['alt' ]));
1357+ padding: EdgeInsets .only (right: 2.0 ), child: Text (node.attributes['alt' ]));
14011358 } else {
14021359 return Text (node.attributes['alt' ]);
14031360 }
@@ -1618,9 +1575,8 @@ class HtmlOldParser extends StatelessWidget {
16181575 painter = new TextPainter (
16191576 text: new TextSpan (
16201577 text: node.text,
1621- style: parentStyle.merge (TextStyle (
1622- fontSize:
1623- parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
1578+ style: parentStyle.merge (
1579+ TextStyle (fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
16241580 ),
16251581 textDirection: TextDirection .ltr);
16261582 painter.layout ();
@@ -1651,8 +1607,7 @@ class HtmlOldParser extends StatelessWidget {
16511607 top: node.localName == "sub" ? null : 0 ,
16521608 ),
16531609 style: TextStyle (
1654- fontSize: parentStyle.fontSize *
1655- OFFSET_TAGS_FONT_SIZE_FACTOR ),
1610+ fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ),
16561611 )
16571612 ],
16581613 )
@@ -1767,8 +1722,7 @@ class HtmlOldParser extends StatelessWidget {
17671722 String finalText = trimStringHtml (node.text);
17681723 //Temp fix for https://github.com/flutter/flutter/issues/736
17691724 if (finalText.endsWith (" " )) {
1770- return Container (
1771- padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
1725+ return Container (padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
17721726 } else {
17731727 return Text (finalText);
17741728 }
0 commit comments