build method

  1. @override
InlineSpan build()
override

Implementation

@override
InlineSpan build() {
  double? width;
  double? height;
  if (attributes['width'] != null) width = double.parse(attributes['width']!);
  if (attributes['height'] != null) {
    height = double.parse(attributes['height']!);
  }
  final imageUrl = attributes['src'] ?? '';
  final alt = attributes['alt'] ?? '';
  final isNetImage = imageUrl.startsWith('http');
  final imgWidget = isNetImage
      ? Image.network(imageUrl,
          width: width,
          height: height,
          fit: BoxFit.cover, errorBuilder: (ctx, error, stacktrace) {
          return buildErrorImage(imageUrl, alt, error);
        })
      : Image.asset(imageUrl, width: width, height: height, fit: BoxFit.cover,
          errorBuilder: (ctx, error, stacktrace) {
          return buildErrorImage(imageUrl, alt, error);
        });
  final result = (parent != null && parent is LinkNode)
      ? imgWidget
      : Builder(builder: (context) {
          return InkWell(
            child: Hero(tag: imgWidget.hashCode, child: imgWidget),
            onTap: () => _showImage(context, imgWidget),
          );
        });
  return WidgetSpan(
      child: imgConfig.builder?.call(imageUrl, attributes) ?? result);
}