build method
Widget
build(
- BuildContext context,
- QuillController controller,
- Embed node,
- bool readOnly,
- bool inline,
override
Implementation
@override
Widget build(
BuildContext context,
QuillController controller,
Embed node,
bool readOnly,
bool inline,
) {
assert(!kIsWeb, 'Please provide image EmbedBuilder for Web');
Widget image = const SizedBox();
final imageUrl = standardizeImageUrl(node.value.data);
OptionalSize? _imageSize;
final style = node.style.attributes['style'];
if (style != null) {
final _attrs = parseKeyValuePairs(style.value.toString(),
{Attribute.mobileWidth, Attribute.mobileHeight, Attribute.mobileMargin, Attribute.mobileAlignment});
if (_attrs.isNotEmpty) {
assert(_attrs[Attribute.mobileWidth] != null && _attrs[Attribute.mobileHeight] != null,
'mobileWidth and mobileHeight must be specified');
final w = double.parse(_attrs[Attribute.mobileWidth]!);
final h = double.parse(_attrs[Attribute.mobileHeight]!);
_imageSize = OptionalSize(w, h);
final m = _attrs[Attribute.mobileMargin] == null ? 0.0 : double.parse(_attrs[Attribute.mobileMargin]!);
final a = getAlignment(_attrs[Attribute.mobileAlignment]);
image = Padding(padding: EdgeInsets.all(m), child: imageByUrl(imageUrl, width: w, height: h, alignment: a));
}
}
if (_imageSize == null) {
image = imageByUrl(imageUrl);
_imageSize = OptionalSize((image as Image).width, image.height);
}
if (!readOnly) {
double width = _imageSize.width ?? 0;
double height = _imageSize.height ?? 0;
double maxWidth = MediaUtils.instance.screenWidth;
double maxHeight = (width == 0 || height == 0) ? 0 : (maxWidth * height / width);
if (maxHeight == 0) {
maxHeight = MediaUtils.instance.screenHeight;
}
if (width == 0) {
width = maxWidth;
}
if (height == 0) {
height = width * maxHeight / maxWidth;
}
return GestureDetector(
onTap: () => ImageSettingDialogs.instance.show(
context: context,
width: width,
height: height,
maxWidth: maxWidth,
maxHeight: maxHeight,
controller: controller,
removeImageCall: removeImageCall),
child: image,
);
}
return image;
}