我想在flutter web中使用富文本编辑器,但在flutter web中找不到类似的编辑器。所以我想如果我能在flutter web中实现froala编辑器。那么有没有可能将froala-editor的javascript库插入到flutter web中呢?
https://froala.com/wysiwyg-editor/
是否可以在flutter web中使用froala-editor,或者是否有其他方法可以在flutter web中获得富文本编辑器?
提前谢谢。
发布于 2021-03-02 14:01:03
是的,这是可能的,伙计!但是你可以暂时使用它,直到颤动网变得稳定。
诀窍是,你可以使用froala或Quill任何普通html编辑器,你可以在Flutter IFrame元素中呈现它,你可以通过Js连接器传递数据,反之亦然。
示例代码如下:
import 'dart:js' as js;
js.JsObject connector;
js.IFrameElement element;
String createdViewId = 'map_element';
js.context["connect_content_to_flutter"] = (js.JsObject content) {
connector = content;
};
element = html.IFrameElement()
..src = "/assets/assets/editor.html"
..style.border = 'none';
ui.platformViewRegistry
.registerViewFactory(createdViewId, (int viewId) => element);
// SO the above code defines your plain html(Place inside the Project folder ex:assets/editor.html) and registered with UI, now you can use the HTMLElementView(Widget) to render the view in screen.
HtmlElementView(
viewType: createdViewId,
);
// Now in your html file
Sample
span.fr-emoticon{
background-repeat: no-repeat !important;
font-size: 28px;
}
(function () {
new FroalaEditor("#edit", {
theme: 'royal',
height: 450
})
})()
parent.connect_content_to_flutter && parent.connect_content_to_flutter(window)
function getValue(){
return $('#edit').val();
}
window.addEventListener("message", (message) => {
if (message.data.id === "value") {
quill.root.innerHTML = message.data.msg;
}
})
// Above parent connect to flutter is very important line that you should include because that is the one connecting to flutter and the window listener is listening for sending the data from flutter.
//so in your dart
connector.callMethod(
'getValue',
) as String;
element.contentWindow.postMessage({
'id': 'value',
'msg': "Hi /n Welcome sending data from dart",
}, "*");是的,go.Happy编码不错!
https://stackoverflow.com/questions/61905987
复制相似问题