@@ -32,11 +32,7 @@ class LinkTextSpan extends TextSpan {
32
32
final String url;
33
33
34
34
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})
40
36
: super (
41
37
style: style,
42
38
text: text,
@@ -80,11 +76,7 @@ class BlockText extends StatelessWidget {
80
76
final Decoration decoration;
81
77
82
78
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});
88
80
89
81
@override
90
82
Widget build (BuildContext context) {
@@ -255,8 +247,7 @@ class HtmlRichTextParser extends StatelessWidget {
255
247
bool _hasBlockChild (dom.Node node, {bool ignoreSelf = true }) {
256
248
bool retval = false ;
257
249
if (node is dom.Element ) {
258
- if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf)
259
- return true ;
250
+ if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf) return true ;
260
251
node.nodes.forEach ((dom.Node node) {
261
252
if (_hasBlockChild (node, ignoreSelf: false )) retval = true ;
262
253
});
@@ -291,8 +282,7 @@ class HtmlRichTextParser extends StatelessWidget {
291
282
if (w is BlockText ) {
292
283
if (w.child.text == null ) return ;
293
284
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 ;
296
286
} else if (w is LinkBlock ) {
297
287
if (w.children.isEmpty) return ;
298
288
} else if (w is LinkTextSpan ) {
@@ -319,8 +309,7 @@ class HtmlRichTextParser extends StatelessWidget {
319
309
// function can add child nodes to the parent if it should
320
310
//
321
311
// 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) {
324
313
// TEXT ONLY NODES
325
314
// a text only node is a child of a tag with no inner html
326
315
if (node is dom.Text ) {
@@ -359,18 +348,15 @@ class HtmlRichTextParser extends StatelessWidget {
359
348
// debugPrint("Plain Text Node: '$finalText'");
360
349
361
350
// 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);
366
353
367
354
// in this class, a ParentElement must be a BlockText, LinkTextSpan, Row, Column, TextSpan
368
355
369
356
// the parseContext might actually be a block level style element, so we
370
357
// need to honor the indent and styling specified by that block style.
371
358
// 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 ;
374
360
375
361
// if there is no parentElement, contain the span in a BlockText
376
362
if (parseContext.parentElement == null ) {
@@ -381,18 +367,15 @@ class HtmlRichTextParser extends StatelessWidget {
381
367
Decoration decoration;
382
368
if (parseContext.blockType == 'blockquote' ) {
383
369
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 )),
386
371
);
387
372
parseContext.childStyle = parseContext.childStyle.merge (TextStyle (
388
373
fontStyle: FontStyle .italic,
389
374
));
390
375
}
391
376
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),
396
379
padding: EdgeInsets .all (2.0 ),
397
380
decoration: decoration,
398
381
child: RichText (
@@ -402,8 +385,7 @@ class HtmlRichTextParser extends StatelessWidget {
402
385
);
403
386
parseContext.rootWidgetList.add (blockText);
404
387
} else {
405
- parseContext.rootWidgetList
406
- .add (BlockText (child: RichText (text: span)));
388
+ parseContext.rootWidgetList.add (BlockText (child: RichText (text: span)));
407
389
}
408
390
409
391
// this allows future items to be added as children of this item
@@ -413,8 +395,7 @@ class HtmlRichTextParser extends StatelessWidget {
413
395
} else if (parseContext.parentElement is LinkTextSpan ) {
414
396
// add this node to the parent as another LinkTextSpan
415
397
parseContext.parentElement.children.add (LinkTextSpan (
416
- style:
417
- parseContext.parentElement.style.merge (parseContext.childStyle),
398
+ style: parseContext.parentElement.style.merge (parseContext.childStyle),
418
399
url: parseContext.parentElement.url,
419
400
text: finalText,
420
401
onLinkTap: onLinkTap,
@@ -447,21 +428,18 @@ class HtmlRichTextParser extends StatelessWidget {
447
428
//"b","i","em","strong","code","u","small","abbr","acronym"
448
429
case "b" :
449
430
case "strong" :
450
- childStyle =
451
- childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
431
+ childStyle = childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
452
432
break ;
453
433
case "i" :
454
434
case "address" :
455
435
case "em" :
456
- childStyle =
457
- childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
436
+ childStyle = childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
458
437
break ;
459
438
case "code" :
460
439
childStyle = childStyle.merge (TextStyle (fontFamily: 'monospace' ));
461
440
break ;
462
441
case "u" :
463
- childStyle = childStyle
464
- .merge (TextStyle (decoration: TextDecoration .underline));
442
+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .underline));
465
443
break ;
466
444
case "abbr" :
467
445
case "acronym" :
@@ -518,8 +496,7 @@ class HtmlRichTextParser extends StatelessWidget {
518
496
if (_hasBlockChild (node)) {
519
497
LinkBlock linkContainer = LinkBlock (
520
498
url: url,
521
- margin: EdgeInsets .only (
522
- left: parseContext.indentLevel * indentSize),
499
+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize),
523
500
onLinkTap: onLinkTap,
524
501
children: < Widget > [],
525
502
);
@@ -538,8 +515,7 @@ class HtmlRichTextParser extends StatelessWidget {
538
515
} else {
539
516
// start a new block element for this link and its text
540
517
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 ),
543
519
child: RichText (text: span),
544
520
);
545
521
parseContext.rootWidgetList.add (blockElement);
@@ -551,10 +527,8 @@ class HtmlRichTextParser extends StatelessWidget {
551
527
break ;
552
528
553
529
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: []));
558
532
}
559
533
break ;
560
534
@@ -566,8 +540,7 @@ class HtmlRichTextParser extends StatelessWidget {
566
540
children: < Widget > [],
567
541
);
568
542
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));
571
544
break ;
572
545
573
546
// we don't handle tbody, thead, or tfoot elements separately for now
@@ -583,11 +556,8 @@ class HtmlRichTextParser extends StatelessWidget {
583
556
colspan = int .tryParse (node.attributes['colspan' ]);
584
557
}
585
558
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 > []));
591
561
Expanded cell = Expanded (
592
562
flex: colspan,
593
563
child: Container (padding: EdgeInsets .all (1.0 ), child: text),
@@ -642,8 +612,7 @@ class HtmlRichTextParser extends StatelessWidget {
642
612
643
613
switch (node.localName) {
644
614
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));
647
616
break ;
648
617
case "img" :
649
618
if (node.attributes['src' ] != null ) {
@@ -666,7 +635,6 @@ class HtmlRichTextParser extends StatelessWidget {
666
635
scale: imageProperties? .scale ?? 1.0 ,
667
636
matchTextDirection: imageProperties? .matchTextDirection ?? false ,
668
637
centerSlice: imageProperties? .centerSlice,
669
- gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
670
638
filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
671
639
alignment: imageProperties? .alignment ?? Alignment .center,
672
640
colorBlendMode: imageProperties? .colorBlendMode,
@@ -692,7 +660,6 @@ class HtmlRichTextParser extends StatelessWidget {
692
660
scale: imageProperties? .scale ?? 1.0 ,
693
661
matchTextDirection: imageProperties? .matchTextDirection ?? false ,
694
662
centerSlice: imageProperties? .centerSlice,
695
- gaplessPlayback: imageProperties? .gaplessPlayback ?? false ,
696
663
filterQuality: imageProperties? .filterQuality ?? FilterQuality .low,
697
664
alignment: imageProperties? .alignment ?? Alignment .center,
698
665
colorBlendMode: imageProperties? .colorBlendMode,
@@ -728,8 +695,7 @@ class HtmlRichTextParser extends StatelessWidget {
728
695
leadingChar = parseContext.listCount.toString () + '.' ;
729
696
}
730
697
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 ),
733
699
child: RichText (
734
700
text: TextSpan (
735
701
text: '' ,
@@ -790,8 +756,7 @@ class HtmlRichTextParser extends StatelessWidget {
790
756
Decoration decoration;
791
757
if (parseContext.blockType == 'blockquote' ) {
792
758
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 )),
795
760
);
796
761
nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
797
762
fontStyle: FontStyle .italic,
@@ -800,9 +765,7 @@ class HtmlRichTextParser extends StatelessWidget {
800
765
BlockText blockText = BlockText (
801
766
margin: _customEdgeInsets ??
802
767
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),
806
769
padding: EdgeInsets .all (2.0 ),
807
770
decoration: decoration,
808
771
child: RichText (
@@ -1012,8 +975,7 @@ class HtmlOldParser extends StatelessWidget {
1012
975
1013
976
Widget _parseNode (dom.Node node) {
1014
977
if (customRender != null ) {
1015
- final Widget customWidget =
1016
- customRender (node, _parseNodeList (node.nodes));
978
+ final Widget customWidget = customRender (node, _parseNodeList (node.nodes));
1017
979
if (customWidget != null ) {
1018
980
return customWidget;
1019
981
}
@@ -1103,9 +1065,8 @@ class HtmlOldParser extends StatelessWidget {
1103
1065
child: Wrap (
1104
1066
children: _parseNodeList (node.nodes),
1105
1067
),
1106
- textDirection: node.attributes["dir" ] == "rtl"
1107
- ? TextDirection .rtl
1108
- : TextDirection .ltr,
1068
+ textDirection:
1069
+ node.attributes["dir" ] == "rtl" ? TextDirection .rtl : TextDirection .ltr,
1109
1070
);
1110
1071
}
1111
1072
//Direction attribute is required, just render the text normally now.
@@ -1123,8 +1084,7 @@ class HtmlOldParser extends StatelessWidget {
1123
1084
);
1124
1085
case "blockquote" :
1125
1086
return Padding (
1126
- padding:
1127
- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1087
+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1128
1088
child: Container (
1129
1089
width: width,
1130
1090
child: Wrap (
@@ -1247,8 +1207,7 @@ class HtmlOldParser extends StatelessWidget {
1247
1207
);
1248
1208
case "figure" :
1249
1209
return Padding (
1250
- padding:
1251
- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1210
+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1252
1211
child: Column (
1253
1212
children: _parseNodeList (node.nodes),
1254
1213
crossAxisAlignment: CrossAxisAlignment .center,
@@ -1378,13 +1337,12 @@ class HtmlOldParser extends StatelessWidget {
1378
1337
if (node.attributes['src' ].startsWith ("data:image" ) &&
1379
1338
node.attributes['src' ].contains ("base64," )) {
1380
1339
precacheImage (
1381
- MemoryImage (base64.decode (
1382
- node.attributes['src' ].split ("base64," )[1 ].trim ())),
1340
+ MemoryImage (base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ())),
1383
1341
context,
1384
1342
onError: onImageError,
1385
1343
);
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 ()));
1388
1346
}
1389
1347
precacheImage (
1390
1348
NetworkImage (node.attributes['src' ]),
@@ -1396,8 +1354,7 @@ class HtmlOldParser extends StatelessWidget {
1396
1354
//Temp fix for https://github.com/flutter/flutter/issues/736
1397
1355
if (node.attributes['alt' ].endsWith (" " )) {
1398
1356
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' ]));
1401
1358
} else {
1402
1359
return Text (node.attributes['alt' ]);
1403
1360
}
@@ -1618,9 +1575,8 @@ class HtmlOldParser extends StatelessWidget {
1618
1575
painter = new TextPainter (
1619
1576
text: new TextSpan (
1620
1577
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 )),
1624
1580
),
1625
1581
textDirection: TextDirection .ltr);
1626
1582
painter.layout ();
@@ -1651,8 +1607,7 @@ class HtmlOldParser extends StatelessWidget {
1651
1607
top: node.localName == "sub" ? null : 0 ,
1652
1608
),
1653
1609
style: TextStyle (
1654
- fontSize: parentStyle.fontSize *
1655
- OFFSET_TAGS_FONT_SIZE_FACTOR ),
1610
+ fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ),
1656
1611
)
1657
1612
],
1658
1613
)
@@ -1767,8 +1722,7 @@ class HtmlOldParser extends StatelessWidget {
1767
1722
String finalText = trimStringHtml (node.text);
1768
1723
//Temp fix for https://github.com/flutter/flutter/issues/736
1769
1724
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));
1772
1726
} else {
1773
1727
return Text (finalText);
1774
1728
}
0 commit comments