1
+ import 'package:collection/collection.dart' ;
1
2
2
3
import 'dart:async' ;
3
4
import 'dart:convert' ;
@@ -11,7 +12,8 @@ import 'package:flutter_html/src/utils.dart';
11
12
typedef CustomRenderMatcher = bool Function (RenderContext context);
12
13
13
14
CustomRenderMatcher blockElementMatcher () => (context) {
14
- return context.tree.style.display == Display .BLOCK ;
15
+ return context.tree.style.display == Display .BLOCK
16
+ && context.tree.children.isNotEmpty;
15
17
};
16
18
17
19
CustomRenderMatcher listElementMatcher () => (context) {
@@ -99,8 +101,22 @@ CustomRender blockElementRender({
99
101
newContext: context,
100
102
style: style ?? context.tree.style,
101
103
shrinkWrap: context.parser.shrinkWrap,
102
- child: child,
103
- children: children ?? buildChildren.call (),
104
+ children: children ?? context.tree.children
105
+ .expandIndexed ((i, childTree) => [
106
+ if (context.parser.shrinkWrap &&
107
+ childTree.style.display == Display .BLOCK &&
108
+ i > 0 &&
109
+ context.tree.children[i - 1 ] is ReplacedElement )
110
+ TextSpan (text: "\n " ),
111
+ context.parser.parseTree (context, childTree),
112
+ if (context.parser.shrinkWrap &&
113
+ i != context.tree.children.length - 1 &&
114
+ childTree.style.display == Display .BLOCK &&
115
+ childTree.element? .localName != "html" &&
116
+ childTree.element? .localName != "body" )
117
+ TextSpan (text: "\n " ),
118
+ ])
119
+ .toList (),
104
120
),
105
121
));
106
122
@@ -354,8 +370,16 @@ CustomRender verticalAlignRender({
354
370
355
371
CustomRender fallbackRender ({Style ? style, List <InlineSpan >? children}) =>
356
372
CustomRender .fromInlineSpan (inlineSpan: (context, buildChildren) => TextSpan (
357
- style: style? .generateTextStyle () ?? context.style.generateTextStyle (),
358
- children: children ?? buildChildren.call (),
373
+ style: style? .generateTextStyle () ?? context.style.generateTextStyle (),
374
+ children: context.tree.children
375
+ .expand ((tree) => [
376
+ context.parser.parseTree (context, tree),
377
+ if (tree.style.display == Display .BLOCK &&
378
+ tree.element? .localName != "html" &&
379
+ tree.element? .localName != "body" )
380
+ TextSpan (text: "\n " ),
381
+ ])
382
+ .toList (),
359
383
));
360
384
361
385
final Map <CustomRenderMatcher , CustomRender > defaultRenders = {
@@ -401,21 +425,17 @@ InlineSpan _getInteractableChildren(RenderContext context, InteractableElement t
401
425
);
402
426
} else {
403
427
return WidgetSpan (
404
- child: RawGestureDetector (
405
- key: context.key,
406
- gestures: {
407
- MultipleTapGestureRecognizer :
408
- GestureRecognizerFactoryWithHandlers <MultipleTapGestureRecognizer >(
409
- () => MultipleTapGestureRecognizer (),
410
- (instance) {
411
- instance
412
- ..onTap = context.parser.onAnchorTap != null
413
- ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
414
- : null ;
415
- },
416
- ),
417
- },
418
- child: (childSpan as WidgetSpan ).child,
428
+ child: MultipleTapGestureDetector (
429
+ onTap: context.parser.onAnchorTap != null
430
+ ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
431
+ : null ,
432
+ child: GestureDetector (
433
+ key: context.key,
434
+ onTap: context.parser.onAnchorTap != null
435
+ ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
436
+ : null ,
437
+ child: (childSpan as WidgetSpan ).child,
438
+ ),
419
439
),
420
440
);
421
441
}
0 commit comments