span method
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');
}
final Widget image;
if (config.imageBuilder != null) {
image = config.imageBuilder!(context, '${match?[2]}');
} else {
image = 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();
},
),
);
}
return WidgetSpan(alignment: PlaceholderAlignment.bottom, child: image);
}