diff --git a/example/assets/sample_data.json b/example/assets/sample_data.json index ee1857d0..6fba6e1d 100644 --- a/example/assets/sample_data.json +++ b/example/assets/sample_data.json @@ -14,7 +14,7 @@ }, "attributes":{ "width":"230", - "style":"display: block; margin: auto;" + "style":"display: block; margin: auto; mobileWidth: 5; mobileHeight: 5; mobileMargin: 1;" } }, { diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 5cf89f1d..fa39aa14 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -97,12 +97,34 @@ String _standardizeImageUrl(String url) { return url; } +bool _isMobile() => io.Platform.isAndroid || io.Platform.isIOS; + Widget _defaultEmbedBuilder( BuildContext context, leaf.Embed node, bool readOnly) { assert(!kIsWeb, 'Please provide EmbedBuilder for Web'); switch (node.value.type) { case 'image': final imageUrl = _standardizeImageUrl(node.value.data); + + final style = node.style.attributes['style']; + if (_isMobile() && style != null) { + final imageStyles = style.value.toString().split(';'); + final _keys = {'mobileWidth', 'mobileHeight', 'mobileMargin'}; + final _attrs = {}; + for (final imageStyle in imageStyles) { + final _index = imageStyle.indexOf(':'); + if (_index < 0) { + continue; + } + final _key = imageStyle.substring(0, _index).trim(); + if (_keys.contains(_key)) { + _attrs[_key] = imageStyle.substring(_index + 1).trim(); + } + } + if (_attrs.isNotEmpty) { + // TODO: return image with custom width, height and margin + } + } return imageUrl.startsWith('http') ? Image.network(imageUrl) : isBase64(imageUrl)