|
|
@ -1,13 +1,15 @@ |
|
|
|
import 'package:flutter/foundation.dart' show kIsWeb; |
|
|
|
import 'package:flutter/foundation.dart' show kIsWeb; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
|
|
|
|
import 'package:flutter_quill/extensions.dart' as base; |
|
|
|
import 'package:flutter_quill/flutter_quill.dart'; |
|
|
|
import 'package:flutter_quill/flutter_quill.dart'; |
|
|
|
import 'package:universal_html/html.dart' as html; |
|
|
|
import 'package:universal_html/html.dart' as html; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import '../../utils.dart'; |
|
|
|
import 'shims/dart_ui_fake.dart' |
|
|
|
import 'shims/dart_ui_fake.dart' |
|
|
|
if (dart.library.html) 'shims/dart_ui_real.dart' as ui; |
|
|
|
if (dart.library.html) 'shims/dart_ui_real.dart' as ui; |
|
|
|
|
|
|
|
|
|
|
|
class ImageEmbedBuilderWeb extends EmbedBuilder { |
|
|
|
class QuillEditorWebImageEmbedBuilder extends EmbedBuilder { |
|
|
|
const ImageEmbedBuilderWeb({ |
|
|
|
const QuillEditorWebImageEmbedBuilder({ |
|
|
|
this.constraints, |
|
|
|
this.constraints, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -28,11 +30,37 @@ class ImageEmbedBuilderWeb extends EmbedBuilder { |
|
|
|
assert(kIsWeb, 'ImageEmbedBuilderWeb is only for web platform'); |
|
|
|
assert(kIsWeb, 'ImageEmbedBuilderWeb is only for web platform'); |
|
|
|
final imageUrl = node.value.data; |
|
|
|
final imageUrl = node.value.data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isImageBase64(imageUrl)) { |
|
|
|
|
|
|
|
// TODO: handle imageUrl of base64 |
|
|
|
|
|
|
|
return const Text('Image base 64 is not supported yet.'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var height = 'auto'; |
|
|
|
|
|
|
|
var width = 'auto'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final style = node.style.attributes['style']; |
|
|
|
|
|
|
|
if (style != null) { |
|
|
|
|
|
|
|
final attrs = base.parseKeyValuePairs(style.value.toString(), { |
|
|
|
|
|
|
|
Attribute.width.key, |
|
|
|
|
|
|
|
Attribute.height.key, |
|
|
|
|
|
|
|
Attribute.margin, |
|
|
|
|
|
|
|
Attribute.alignment, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
final heightValue = attrs[Attribute.height.key]; |
|
|
|
|
|
|
|
if (heightValue != null) { |
|
|
|
|
|
|
|
height = heightValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final widthValue = attrs[Attribute.width.key]; |
|
|
|
|
|
|
|
if (widthValue != null) { |
|
|
|
|
|
|
|
width = widthValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ui.PlatformViewRegistry().registerViewFactory(imageUrl, (viewId) { |
|
|
|
ui.PlatformViewRegistry().registerViewFactory(imageUrl, (viewId) { |
|
|
|
return html.ImageElement() |
|
|
|
return html.ImageElement() |
|
|
|
..src = imageUrl |
|
|
|
..src = imageUrl |
|
|
|
..style.height = 'auto' |
|
|
|
..style.height = height |
|
|
|
..style.width = 'auto'; |
|
|
|
..style.width = width; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return ConstrainedBox( |
|
|
|
return ConstrainedBox( |
|
|
|