1
-
1
+ import 'package:collection/collection.dart' ;
2
2
import 'package:flutter/gestures.dart' ;
3
3
import 'package:flutter/material.dart' ;
4
4
import 'package:flutter_html/flutter_html.dart' ;
@@ -8,7 +8,8 @@ import 'package:flutter_html/src/utils.dart';
8
8
typedef CustomRenderMatcher = bool Function (RenderContext context);
9
9
10
10
CustomRenderMatcher blockElementMatcher () => (context) {
11
- return context.tree.style.display == Display .BLOCK ;
11
+ return context.tree.style.display == Display .BLOCK
12
+ && context.tree.children.isNotEmpty;
12
13
};
13
14
14
15
CustomRenderMatcher listElementMatcher () => (context) {
@@ -64,8 +65,22 @@ CustomRender blockElementRender({
64
65
newContext: context,
65
66
style: style ?? context.tree.style,
66
67
shrinkWrap: context.parser.shrinkWrap,
67
- child: child,
68
- children: children ?? buildChildren.call (),
68
+ children: children ?? context.tree.children
69
+ .expandIndexed ((i, childTree) => [
70
+ if (context.parser.shrinkWrap &&
71
+ childTree.style.display == Display .BLOCK &&
72
+ i > 0 &&
73
+ context.tree.children[i - 1 ] is ReplacedElement )
74
+ TextSpan (text: "\n " ),
75
+ context.parser.parseTree (context, childTree),
76
+ if (context.parser.shrinkWrap &&
77
+ i != context.tree.children.length - 1 &&
78
+ childTree.style.display == Display .BLOCK &&
79
+ childTree.element? .localName != "html" &&
80
+ childTree.element? .localName != "body" )
81
+ TextSpan (text: "\n " ),
82
+ ])
83
+ .toList (),
69
84
),
70
85
));
71
86
@@ -168,8 +183,16 @@ CustomRender verticalAlignRender({
168
183
169
184
CustomRender fallbackRender ({Style ? style, List <InlineSpan >? children}) =>
170
185
CustomRender .fromInlineSpan (inlineSpan: (context, buildChildren) => TextSpan (
171
- style: style? .generateTextStyle () ?? context.style.generateTextStyle (),
172
- children: children ?? buildChildren.call (),
186
+ style: style? .generateTextStyle () ?? context.style.generateTextStyle (),
187
+ children: context.tree.children
188
+ .expand ((tree) => [
189
+ context.parser.parseTree (context, tree),
190
+ if (tree.style.display == Display .BLOCK &&
191
+ tree.element? .localName != "html" &&
192
+ tree.element? .localName != "body" )
193
+ TextSpan (text: "\n " ),
194
+ ])
195
+ .toList (),
173
196
));
174
197
175
198
final Map <CustomRenderMatcher , CustomRender > defaultRenders = {
@@ -212,21 +235,17 @@ InlineSpan _getInteractableChildren(RenderContext context, InteractableElement t
212
235
);
213
236
} else {
214
237
return WidgetSpan (
215
- child: RawGestureDetector (
216
- key: context.key,
217
- gestures: {
218
- MultipleTapGestureRecognizer :
219
- GestureRecognizerFactoryWithHandlers <MultipleTapGestureRecognizer >(
220
- () => MultipleTapGestureRecognizer (),
221
- (instance) {
222
- instance
223
- ..onTap = context.parser.onAnchorTap != null
224
- ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
225
- : null ;
226
- },
227
- ),
228
- },
229
- child: (childSpan as WidgetSpan ).child,
238
+ child: MultipleTapGestureDetector (
239
+ onTap: context.parser.onAnchorTap != null
240
+ ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
241
+ : null ,
242
+ child: GestureDetector (
243
+ key: context.key,
244
+ onTap: context.parser.onAnchorTap != null
245
+ ? () => context.parser.onAnchorTap !(tree.href, context, tree.attributes, tree.element)
246
+ : null ,
247
+ child: (childSpan as WidgetSpan ).child,
248
+ ),
230
249
),
231
250
);
232
251
}
0 commit comments