@@ -33,11 +33,7 @@ class LinkTextSpan extends TextSpan {
3333 final String url;
3434
3535 LinkTextSpan (
36- {TextStyle style,
37- this .url,
38- String text,
39- OnLinkTap onLinkTap,
40- List <TextSpan > children})
36+ {TextStyle style, this .url, String text, OnLinkTap onLinkTap, List <TextSpan > children})
4137 : super (
4238 style: style,
4339 text: text,
@@ -81,11 +77,7 @@ class BlockText extends StatelessWidget {
8177 final Decoration decoration;
8278
8379 BlockText (
84- {@required this .child,
85- this .padding,
86- this .margin,
87- this .leadingChar = '' ,
88- this .decoration});
80+ {@required this .child, this .padding, this .margin, this .leadingChar = '' , this .decoration});
8981
9082 @override
9183 Widget build (BuildContext context) {
@@ -279,8 +271,7 @@ class HtmlRichTextParser extends StatelessWidget {
279271 bool _hasBlockChild (dom.Node node, {bool ignoreSelf = true }) {
280272 bool retval = false ;
281273 if (node is dom.Element ) {
282- if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf)
283- return true ;
274+ if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf) return true ;
284275 node.nodes.forEach ((dom.Node node) {
285276 if (_hasBlockChild (node, ignoreSelf: false )) retval = true ;
286277 });
@@ -315,8 +306,7 @@ class HtmlRichTextParser extends StatelessWidget {
315306 if (w is BlockText ) {
316307 if (w.child.text == null ) return ;
317308 if ((w.child.text.text == null || w.child.text.text.isEmpty) &&
318- (w.child.text.children == null || w.child.text.children.isEmpty))
319- return ;
309+ (w.child.text.children == null || w.child.text.children.isEmpty)) return ;
320310 } else if (w is LinkBlock ) {
321311 if (w.children.isEmpty) return ;
322312 } else if (w is LinkTextSpan ) {
@@ -343,8 +333,7 @@ class HtmlRichTextParser extends StatelessWidget {
343333 // function can add child nodes to the parent if it should
344334 //
345335 // each iteration creates a new parseContext as a copy of the previous one if it needs to
346- void _parseNode (
347- dom.Node node, ParseContext parseContext, BuildContext buildContext) {
336+ void _parseNode (dom.Node node, ParseContext parseContext, BuildContext buildContext) {
348337 // TEXT ONLY NODES
349338 // a text only node is a child of a tag with no inner html
350339 if (node is dom.Text ) {
@@ -383,18 +372,15 @@ class HtmlRichTextParser extends StatelessWidget {
383372 // debugPrint("Plain Text Node: '$finalText'");
384373
385374 // create a span by default
386- TextSpan span = TextSpan (
387- text: finalText,
388- children: < TextSpan > [],
389- style: parseContext.childStyle);
375+ TextSpan span =
376+ TextSpan (text: finalText, children: < TextSpan > [], style: parseContext.childStyle);
390377
391378 // in this class, a ParentElement must be a BlockText, LinkTextSpan, Row, Column, TextSpan
392379
393380 // the parseContext might actually be a block level style element, so we
394381 // need to honor the indent and styling specified by that block style.
395382 // e.g. ol, ul, blockquote
396- bool treatLikeBlock =
397- ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
383+ bool treatLikeBlock = ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
398384
399385 // if there is no parentElement, contain the span in a BlockText
400386 if (parseContext.parentElement == null ) {
@@ -405,18 +391,15 @@ class HtmlRichTextParser extends StatelessWidget {
405391 Decoration decoration;
406392 if (parseContext.blockType == 'blockquote' ) {
407393 decoration = BoxDecoration (
408- border:
409- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
394+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
410395 );
411396 parseContext.childStyle = parseContext.childStyle.merge (TextStyle (
412397 fontStyle: FontStyle .italic,
413398 ));
414399 }
415400 BlockText blockText = BlockText (
416- margin: EdgeInsets .only (
417- top: 8.0 ,
418- bottom: 8.0 ,
419- left: parseContext.indentLevel * indentSize),
401+ margin:
402+ EdgeInsets .only (top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
420403 padding: EdgeInsets .all (2.0 ),
421404 decoration: decoration,
422405 child: RichText (
@@ -426,8 +409,7 @@ class HtmlRichTextParser extends StatelessWidget {
426409 );
427410 parseContext.rootWidgetList.add (blockText);
428411 } else {
429- parseContext.rootWidgetList
430- .add (BlockText (child: RichText (text: span)));
412+ parseContext.rootWidgetList.add (BlockText (child: RichText (text: span)));
431413 }
432414
433415 // this allows future items to be added as children of this item
@@ -437,8 +419,7 @@ class HtmlRichTextParser extends StatelessWidget {
437419 } else if (parseContext.parentElement is LinkTextSpan ) {
438420 // add this node to the parent as another LinkTextSpan
439421 parseContext.parentElement.children.add (LinkTextSpan (
440- style:
441- parseContext.parentElement.style.merge (parseContext.childStyle),
422+ style: parseContext.parentElement.style.merge (parseContext.childStyle),
442423 url: parseContext.parentElement.url,
443424 text: finalText,
444425 onLinkTap: onLinkTap,
@@ -471,16 +452,14 @@ class HtmlRichTextParser extends StatelessWidget {
471452 //"b","i","em","strong","code","u","small","abbr","acronym"
472453 case "b" :
473454 case "strong" :
474- childStyle =
475- childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
455+ childStyle = childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
476456 break ;
477457 case "i" :
478458 case "address" :
479459 case "cite" :
480460 case "var" :
481461 case "em" :
482- childStyle =
483- childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
462+ childStyle = childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
484463 break ;
485464 case "kbd" :
486465 case "samp" :
@@ -490,8 +469,7 @@ class HtmlRichTextParser extends StatelessWidget {
490469 break ;
491470 case "ins" :
492471 case "u" :
493- childStyle = childStyle
494- .merge (TextStyle (decoration: TextDecoration .underline));
472+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .underline));
495473 break ;
496474 case "abbr" :
497475 case "acronym" :
@@ -507,14 +485,13 @@ class HtmlRichTextParser extends StatelessWidget {
507485 childStyle = childStyle.merge (TextStyle (fontSize: 10.0 ));
508486 break ;
509487 case "mark" :
510- childStyle = childStyle. merge (
511- TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
488+ childStyle =
489+ childStyle. merge ( TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
512490 break ;
513491 case "del" :
514492 case "s" :
515493 case "strike" :
516- childStyle = childStyle
517- .merge (TextStyle (decoration: TextDecoration .lineThrough));
494+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .lineThrough));
518495 break ;
519496 case "ol" :
520497 nextContext.indentLevel += 1 ;
@@ -567,8 +544,7 @@ class HtmlRichTextParser extends StatelessWidget {
567544 if (_hasBlockChild (node)) {
568545 LinkBlock linkContainer = LinkBlock (
569546 url: url,
570- margin: EdgeInsets .only (
571- left: parseContext.indentLevel * indentSize),
547+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize),
572548 onLinkTap: onLinkTap,
573549 children: < Widget > [],
574550 );
@@ -587,8 +563,7 @@ class HtmlRichTextParser extends StatelessWidget {
587563 } else {
588564 // start a new block element for this link and its text
589565 BlockText blockElement = BlockText (
590- margin: EdgeInsets .only (
591- left: parseContext.indentLevel * indentSize, top: 10.0 ),
566+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 10.0 ),
592567 child: RichText (text: span),
593568 );
594569 parseContext.rootWidgetList.add (blockElement);
@@ -600,10 +575,8 @@ class HtmlRichTextParser extends StatelessWidget {
600575 break ;
601576
602577 case "br" :
603- if (parseContext.parentElement != null &&
604- parseContext.parentElement is TextSpan ) {
605- parseContext.parentElement.children
606- .add (TextSpan (text: '\n ' , children: []));
578+ if (parseContext.parentElement != null && parseContext.parentElement is TextSpan ) {
579+ parseContext.parentElement.children.add (TextSpan (text: '\n ' , children: []));
607580 }
608581 break ;
609582
@@ -615,8 +588,7 @@ class HtmlRichTextParser extends StatelessWidget {
615588 children: < Widget > [],
616589 );
617590 nextContext.rootWidgetList.add (Container (
618- margin: EdgeInsets .symmetric (vertical: 12.0 ),
619- child: nextContext.parentElement));
591+ margin: EdgeInsets .symmetric (vertical: 12.0 ), child: nextContext.parentElement));
620592 break ;
621593
622594 // we don't handle tbody, thead, or tfoot elements separately for now
@@ -632,11 +604,8 @@ class HtmlRichTextParser extends StatelessWidget {
632604 colspan = int .tryParse (node.attributes['colspan' ]);
633605 }
634606 nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
635- fontWeight: (node.localName == 'th' )
636- ? FontWeight .bold
637- : FontWeight .normal));
638- RichText text =
639- RichText (text: TextSpan (text: '' , children: < TextSpan > []));
607+ fontWeight: (node.localName == 'th' ) ? FontWeight .bold : FontWeight .normal));
608+ RichText text = RichText (text: TextSpan (text: '' , children: < TextSpan > []));
640609 Expanded cell = Expanded (
641610 flex: colspan,
642611 child: Container (padding: EdgeInsets .all (1.0 ), child: text),
@@ -675,14 +644,11 @@ class HtmlRichTextParser extends StatelessWidget {
675644 nextContext.parentElement = text.text;
676645 break ;
677646 case "q" :
678- if (parseContext.parentElement != null &&
679- parseContext.parentElement is TextSpan ) {
680- parseContext.parentElement.children
681- .add (TextSpan (text: '"' , children: []));
647+ if (parseContext.parentElement != null && parseContext.parentElement is TextSpan ) {
648+ parseContext.parentElement.children.add (TextSpan (text: '"' , children: []));
682649 TextSpan content = TextSpan (text: '' , children: []);
683650 parseContext.parentElement.children.add (content);
684- parseContext.parentElement.children
685- .add (TextSpan (text: '"' , children: []));
651+ parseContext.parentElement.children.add (TextSpan (text: '"' , children: []));
686652 nextContext.parentElement = content;
687653 }
688654 break ;
@@ -703,8 +669,7 @@ class HtmlRichTextParser extends StatelessWidget {
703669
704670 switch (node.localName) {
705671 case "hr" :
706- parseContext.rootWidgetList
707- .add (Divider (height: 1.0 , color: Colors .black38));
672+ parseContext.rootWidgetList.add (Divider (height: 1.0 , color: Colors .black38));
708673 break ;
709674 case "img" :
710675 if (showImages) {
@@ -722,8 +687,7 @@ class HtmlRichTextParser extends StatelessWidget {
722687 );
723688 parseContext.rootWidgetList.add (GestureDetector (
724689 child: Image .memory (
725- base64.decode (
726- node.attributes['src' ].split ("base64," )[1 ].trim ()),
690+ base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ()),
727691 width: imageProperties? .width ??
728692 ((node.attributes['width' ] != null )
729693 ? double .parse (node.attributes['width' ])
@@ -806,8 +770,7 @@ class HtmlRichTextParser extends StatelessWidget {
806770 leadingChar = parseContext.listCount.toString () + '.' ;
807771 }
808772 BlockText blockText = BlockText (
809- margin: EdgeInsets .only (
810- left: parseContext.indentLevel * indentSize, top: 3.0 ),
773+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 3.0 ),
811774 child: RichText (
812775 text: TextSpan (
813776 text: '' ,
@@ -868,8 +831,7 @@ class HtmlRichTextParser extends StatelessWidget {
868831 Decoration decoration;
869832 if (parseContext.blockType == 'blockquote' ) {
870833 decoration = BoxDecoration (
871- border:
872- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
834+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
873835 );
874836 nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
875837 fontStyle: FontStyle .italic,
@@ -879,9 +841,7 @@ class HtmlRichTextParser extends StatelessWidget {
879841 margin: node.localName != 'body'
880842 ? _customEdgeInsets ??
881843 EdgeInsets .only (
882- top: 8.0 ,
883- bottom: 8.0 ,
884- left: parseContext.indentLevel * indentSize)
844+ top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize)
885845 : EdgeInsets .zero,
886846 padding: EdgeInsets .all (2.0 ),
887847 decoration: decoration,
@@ -1070,8 +1030,7 @@ class HtmlOldParser extends StatelessWidget {
10701030
10711031 Widget _parseNode (dom.Node node) {
10721032 if (customRender != null ) {
1073- final Widget customWidget =
1074- customRender (node, _parseNodeList (node.nodes));
1033+ final Widget customWidget = customRender (node, _parseNodeList (node.nodes));
10751034 if (customWidget != null ) {
10761035 return customWidget;
10771036 }
@@ -1161,9 +1120,8 @@ class HtmlOldParser extends StatelessWidget {
11611120 child: Wrap (
11621121 children: _parseNodeList (node.nodes),
11631122 ),
1164- textDirection: node.attributes["dir" ] == "rtl"
1165- ? TextDirection .rtl
1166- : TextDirection .ltr,
1123+ textDirection:
1124+ node.attributes["dir" ] == "rtl" ? TextDirection .rtl : TextDirection .ltr,
11671125 );
11681126 }
11691127 //Direction attribute is required, just render the text normally now.
@@ -1181,8 +1139,7 @@ class HtmlOldParser extends StatelessWidget {
11811139 );
11821140 case "blockquote" :
11831141 return Padding (
1184- padding:
1185- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1142+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
11861143 child: Container (
11871144 width: width,
11881145 child: Wrap (
@@ -1305,8 +1262,7 @@ class HtmlOldParser extends StatelessWidget {
13051262 );
13061263 case "figure" :
13071264 return Padding (
1308- padding:
1309- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1265+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
13101266 child: Column (
13111267 children: _parseNodeList (node.nodes),
13121268 crossAxisAlignment: CrossAxisAlignment .center,
@@ -1437,13 +1393,12 @@ class HtmlOldParser extends StatelessWidget {
14371393 if (node.attributes['src' ].startsWith ("data:image" ) &&
14381394 node.attributes['src' ].contains ("base64," )) {
14391395 precacheImage (
1440- MemoryImage (base64.decode (
1441- node.attributes['src' ].split ("base64," )[1 ].trim ())),
1396+ MemoryImage (base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ())),
14421397 context,
14431398 onError: onImageError,
14441399 );
1445- return Image .memory (base64. decode (
1446- node.attributes['src' ].split ("base64," )[1 ].trim ()));
1400+ return Image .memory (
1401+ base64. decode ( node.attributes['src' ].split ("base64," )[1 ].trim ()));
14471402 }
14481403 precacheImage (
14491404 NetworkImage (node.attributes['src' ]),
@@ -1455,8 +1410,7 @@ class HtmlOldParser extends StatelessWidget {
14551410 //Temp fix for https://github.com/flutter/flutter/issues/736
14561411 if (node.attributes['alt' ].endsWith (" " )) {
14571412 return Container (
1458- padding: EdgeInsets .only (right: 2.0 ),
1459- child: Text (node.attributes['alt' ]));
1413+ padding: EdgeInsets .only (right: 2.0 ), child: Text (node.attributes['alt' ]));
14601414 } else {
14611415 return Text (node.attributes['alt' ]);
14621416 }
@@ -1678,9 +1632,8 @@ class HtmlOldParser extends StatelessWidget {
16781632 painter = new TextPainter (
16791633 text: new TextSpan (
16801634 text: node.text,
1681- style: parentStyle.merge (TextStyle (
1682- fontSize:
1683- parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
1635+ style: parentStyle.merge (
1636+ TextStyle (fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
16841637 ),
16851638 textDirection: TextDirection .ltr);
16861639 painter.layout ();
@@ -1711,8 +1664,7 @@ class HtmlOldParser extends StatelessWidget {
17111664 top: node.localName == "sub" ? null : 0 ,
17121665 ),
17131666 style: TextStyle (
1714- fontSize: parentStyle.fontSize *
1715- OFFSET_TAGS_FONT_SIZE_FACTOR ),
1667+ fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ),
17161668 )
17171669 ],
17181670 )
@@ -1827,8 +1779,7 @@ class HtmlOldParser extends StatelessWidget {
18271779 String finalText = trimStringHtml (node.text);
18281780 //Temp fix for https://github.com/flutter/flutter/issues/736
18291781 if (finalText.endsWith (" " )) {
1830- return Container (
1831- padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
1782+ return Container (padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
18321783 } else {
18331784 return Text (finalText);
18341785 }
0 commit comments