1
+ import 'package:flutter/gestures.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:html/dom.dart' as dom;
3
4
@@ -302,7 +303,7 @@ Widget _buildBlockInlineContainer({
302
303
required BlockInlineContainerNode node,
303
304
}) {
304
305
if (node.links == null ) {
305
- return InlineContent (style: style, nodes: node.nodes);
306
+ return InlineContent (recognizer : null , style: style, nodes: node.nodes);
306
307
}
307
308
return _BlockInlineContainer (
308
309
links: node.links! , style: style, nodes: node.nodes);
@@ -323,21 +324,24 @@ class _BlockInlineContainer extends StatefulWidget {
323
324
class _BlockInlineContainerState extends State <_BlockInlineContainer > {
324
325
@override
325
326
Widget build (BuildContext context) {
326
- return InlineContent (style: widget.style, nodes: widget.nodes);
327
+ return InlineContent (recognizer: null ,
328
+ style: widget.style, nodes: widget.nodes);
327
329
}
328
330
}
329
331
330
332
class InlineContent extends StatelessWidget {
331
333
InlineContent ({
332
334
super .key,
333
- required this .nodes ,
335
+ required this .recognizer ,
334
336
required this .style,
337
+ required this .nodes,
335
338
}) {
336
339
_builder = _InlineContentBuilder (this );
337
340
}
338
341
339
- final List < InlineContentNode > nodes ;
342
+ final GestureRecognizer ? recognizer ;
340
343
final TextStyle ? style;
344
+ final List <InlineContentNode > nodes;
341
345
342
346
late final _InlineContentBuilder _builder;
343
347
@@ -348,14 +352,21 @@ class InlineContent extends StatelessWidget {
348
352
}
349
353
350
354
class _InlineContentBuilder {
351
- _InlineContentBuilder (this .widget);
355
+ _InlineContentBuilder (this .widget) : _recognizer = widget.recognizer ;
352
356
353
357
final InlineContent widget;
354
358
355
359
InlineSpan build () {
356
360
return _buildNodes (widget.nodes, style: widget.style);
357
361
}
358
362
363
+ // Why do we have to track `recognizer` here, rather than apply it
364
+ // once at the top of the affected span? Because the events don't bubble
365
+ // within a paragraph:
366
+ // https://github.com/flutter/flutter/issues/10623
367
+ // https://github.com/flutter/flutter/issues/10623#issuecomment-308030170
368
+ final GestureRecognizer ? _recognizer;
369
+
359
370
InlineSpan _buildNodes (List <InlineContentNode > nodes, {required TextStyle ? style}) {
360
371
return TextSpan (
361
372
style: style,
@@ -364,7 +375,7 @@ class _InlineContentBuilder {
364
375
365
376
InlineSpan _buildNode (InlineContentNode node) {
366
377
if (node is TextNode ) {
367
- return TextSpan (text: node.text);
378
+ return TextSpan (text: node.text, recognizer : _recognizer );
368
379
} else if (node is LineBreakInlineNode ) {
369
380
// Each `<br/>` is followed by a newline, which browsers apparently ignore
370
381
// and our parser doesn't. So don't do anything here.
@@ -401,7 +412,7 @@ class _InlineContentBuilder {
401
412
style: const TextStyle (fontStyle: FontStyle .italic));
402
413
403
414
InlineSpan _buildLink (LinkNode node) {
404
- // TODO make link touchable
415
+ // TODO make link touchable by setting _recognizer
405
416
return _buildNodes (node.nodes,
406
417
style: TextStyle (color: const HSLColor .fromAHSL (1 , 200 , 1 , 0.4 ).toColor ()));
407
418
}
@@ -497,7 +508,11 @@ class UserMention extends StatelessWidget {
497
508
return Container (
498
509
decoration: _kDecoration,
499
510
padding: const EdgeInsets .symmetric (horizontal: 0.2 * kBaseFontSize),
500
- child: InlineContent (nodes: node.nodes, style: null ));
511
+ child: InlineContent (
512
+ // If an @-mention is inside a link, let the @-mention override it.
513
+ recognizer: null , // TODO make @-mentions tappable, for info on user
514
+ style: null ,
515
+ nodes: node.nodes));
501
516
}
502
517
503
518
static get _kDecoration => BoxDecoration (
0 commit comments