add base64 image support in _defaultEmbedBuilder and Remove base64 header from image url (#107)

* Remove base64 header from image url

* change removeBase64Header to _standardizeImageUrl and format code

Co-authored-by: Yahia <yahiaibrahim300@gmail.com>
pull/110/head
yahiaIB 4 years ago committed by GitHub
parent fe7e0a6ba0
commit f62447ef65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      lib/widgets/editor.dart

@ -93,13 +93,22 @@ abstract class RenderAbstractEditor {
void selectPosition(SelectionChangedCause cause);
}
String _standardizeImageUrl(String url) {
if (url.contains("base64")) {
return url.split(",")[1];
}
return url;
}
Widget _defaultEmbedBuilder(BuildContext context, leaf.Embed node) {
switch (node.value.type) {
case 'image':
String imageUrl = node.value.data;
String imageUrl = _standardizeImageUrl(node.value.data);
return imageUrl.startsWith('http')
? Image.network(imageUrl)
: Image.file(io.File(imageUrl));
: isBase64(imageUrl)
? Image.memory(base64.decode(imageUrl))
: Image.file(io.File(imageUrl));
default:
throw UnimplementedError(
'Embeddable type "${node.value.type}" is not supported by default embed '
@ -411,7 +420,7 @@ class _QuillEditorSelectionGestureDetectorBuilder
if (getEditor()!.widget.readOnly && segment.value is BlockEmbed) {
BlockEmbed blockEmbed = segment.value as BlockEmbed;
if (blockEmbed.type == 'image') {
final String imageUrl = blockEmbed.data;
final String imageUrl = _standardizeImageUrl(blockEmbed.data);
Navigator.push(
getEditor()!.context,
MaterialPageRoute(

Loading…
Cancel
Save