首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flutter :在Flutter web中使用Froala-editor

Flutter :在Flutter web中使用Froala-editor
EN

Stack Overflow用户
提问于 2020-05-20 13:51:19
回答 1查看 918关注 0票数 3

我想在flutter web中使用富文本编辑器,但在flutter web中找不到类似的编辑器。所以我想如果我能在flutter web中实现froala编辑器。那么有没有可能将froala-editor的javascript库插入到flutter web中呢?

https://froala.com/wysiwyg-editor/

是否可以在flutter web中使用froala-editor,或者是否有其他方法可以在flutter web中获得富文本编辑器?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-02 14:01:03

是的,这是可能的,伙计!但是你可以暂时使用它,直到颤动网变得稳定。

诀窍是,你可以使用froala或Quill任何普通html编辑器,你可以在Flutter IFrame元素中呈现它,你可以通过Js连接器传递数据,反之亦然。

示例代码如下:

代码语言:javascript
复制
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编码不错!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61905987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档