span method

  1. @override
InlineSpan span(
  1. BuildContext context,
  2. String text,
  3. GptMarkdownConfig config
)
override

Implementation

@override
InlineSpan span(
  BuildContext context,
  String text,
  final GptMarkdownConfig config,
) {
  var match = exp.firstMatch(text.trim());
  double? height;
  double? width;
  if (match?[1] != null) {
    var size = RegExp(r"^([0-9]+)?x?([0-9]+)?")
        .firstMatch(match![1].toString().trim());
    width = double.tryParse(size?[1]?.toString().trim() ?? 'a');
    height = double.tryParse(size?[2]?.toString().trim() ?? 'a');
  }
  return WidgetSpan(
    alignment: PlaceholderAlignment.bottom,
    child: SizedBox(
      width: width,
      height: height,
      child: Image(
        image: NetworkImage(
          "${match?[2]}",
        ),
        loadingBuilder: (BuildContext context, Widget child,
            ImageChunkEvent? loadingProgress) {
          if (loadingProgress == null) {
            return child;
          }
          return CustomImageLoading(
            progress: loadingProgress.expectedTotalBytes != null
                ? loadingProgress.cumulativeBytesLoaded /
                    loadingProgress.expectedTotalBytes!
                : 1,
          );
        },
        fit: BoxFit.fill,
        errorBuilder: (context, error, stackTrace) {
          return const CustomImageError();
        },
      ),
    ),
  );
}