Flutter 有没有办法在FlatterWebView中导入外部脚本

Flutter 有没有办法在FlatterWebView中导入外部脚本,flutter,webview,flutterwebviewplugin,Flutter,Webview,Flutterwebviewplugin,我试图将一个外部脚本加载到FlatterWebView中,但它似乎不起作用。特别是关于tinyMCE的。因此,我们的目的是在内部带有WebView的AlertDialog中打开一个富文本编辑器。可能吗 以下是我的html: <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.2.1/tinymce.min.js"></script> </h

我试图将一个外部脚本加载到FlatterWebView中,但它似乎不起作用。特别是关于tinyMCE的。因此,我们的目的是在内部带有WebView的AlertDialog中打开一个富文本编辑器。可能吗

以下是我的html:

<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.2.1/tinymce.min.js"></script>
</head>
<body>
<textarea id="test"></textarea>
<script>
  tinymce.init({
    selector: 'textarea#test',
    height: 500,
    menubar: false,
    plugins: [
      'advlist autolink lists link image charmap print preview anchor',
      'searchreplace visualblocks code fullscreen',
      'insertdatetime media table paste code help wordcount'
    ],
    toolbar: 'undo redo | formatselect | ' +
    'bold italic backcolor | alignleft aligncenter ' +
    'alignright alignjustify | bullist numlist outdent indent | ' +
    'removeformat | help',
  });
</script>
</body>
</html>

任何帮助都将不胜感激。谢谢

要使
TinyMCE
正常工作,您还需要在HTML的开头添加
(请参阅)

如果我的插件不适用于
webview\u flatter
,你也可以试试我的插件。 它是一个flatter插件,允许您添加内联网络视图或打开应用程序内浏览器窗口,并具有许多事件、方法和选项来控制网络视图

下面是一个使用
initialData:InAppWebViewInitialData()
属性在WebView中插入初始HTML字符串的示例:

导入'dart:async';
进口“包装:颤振/材料.省道”;
导入“包:flatter_inappwebview/flatter_inappwebview.dart”;
Future main()异步{
WidgetsFlutterBinding.ensureInitialized();
runApp(新的MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState扩展了状态{
inappwebview控制器webView;
@凌驾
void initState(){
super.initState();
}
@凌驾
无效处置(){
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(
标题:const Text('InAppWebView示例'),
),
主体:容器(
子项:列(子项:[
扩大(
子:InAppWebView(
initialData:InAppWebViewInitialData(数据:“”
tinymce.init({
选择器:“文本区域#测试”,
身高:500,
梅努巴:错,
插件:[
'advlist autolink列出链接图像charmap打印预览锚',
“searchreplace visualblocks代码全屏显示”,
“insertdatetime媒体表粘贴代码帮助wordcount”
],
工具栏:“撤消重做|格式化选择|”+
“粗体斜体背景色|左对齐居中”+
“alignright alignjustify | bullist numlist outdent indent |”+
“removeformat | help”,
});
"""),
initialHeaders:{},
initialOptions:InAppWebViewGroupOptions(
跨平台:InAppWebViewOptions(
debuggingEnabled:true,
),
android:AndroidAppWebViewOptions(
内置oomcontrols:true
)
),
onWebViewCreated:(InAppWebViewController){
网络视图=控制器;
},
onLoadStart:(InAppWebViewController控制器,字符串url){
},
onLoadStop:(InAppWebViewController控制器,字符串url){
}
))
])),
),
);
}
}
截图:


要使
TinyMCE
正常工作,您还需要在HTML的开头添加
(请参阅)

如果我的插件不适用于
webview\u flatter
,你也可以试试我的插件。 它是一个flatter插件,允许您添加内联网络视图或打开应用程序内浏览器窗口,并具有许多事件、方法和选项来控制网络视图

下面是一个使用
initialData:InAppWebViewInitialData()
属性在WebView中插入初始HTML字符串的示例:

导入'dart:async';
进口“包装:颤振/材料.省道”;
导入“包:flatter_inappwebview/flatter_inappwebview.dart”;
Future main()异步{
WidgetsFlutterBinding.ensureInitialized();
runApp(新的MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState扩展了状态{
inappwebview控制器webView;
@凌驾
void initState(){
super.initState();
}
@凌驾
无效处置(){
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(
标题:const Text('InAppWebView示例'),
),
主体:容器(
子项:列(子项:[
扩大(
子:InAppWebView(
initialData:InAppWebViewInitialData(数据:“”
tinymce.init({
选择器:“文本区域#测试”,
身高:500,
梅努巴:错,
插件:[
'advlist autolink列出链接图像charmap打印预览锚',
“searchreplace visualblocks代码全屏显示”,
“insertdatetime媒体表粘贴代码帮助wordcount”
],
工具栏:“撤消重做|格式化选择|”+
“粗体斜体背景色|左对齐居中”+
“alignright alignjustify | bullist numlist outdent indent |”+
“removeformat | help”,
});
"""),
initialHeaders:{},
initialOptions:InAppWebViewGroupOptions(
跨平台:InAppWebViewOptions(
debuggingEnabled:true,
),
android:AndroidAppWebViewOptions(
内置oomcontrols:true
)
),
onWebViewCreated:(InAppWebViewController){
网络视图=控制器;
},
onLoadStart:(InAppWebViewController控制器,字符串url){
},
onLoadStop:(InAppWebViewController控制器,字符串url){
}
))
])),
),
);
}
}
截图:


我试图在颤振Web中使用您的解决方案,但使用上面的代码,我得到以下错误:1)onLoadStart和onLoadSto的第二个参数
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class RichTextEditor extends StatefulWidget {
  final String html;

  const RichTextEditor({
    this.html: '',
  });

  @override
  RichTextEditorState createState() => RichTextEditorState();
}

class RichTextEditorState extends State<RichTextEditor> {
  WebViewController _webViewController;

  @override
  Widget build(BuildContext context) {
    final String source = Uri.dataFromString(
      widget.html,
      mimeType: 'text/html',
      encoding: Encoding.getByName('utf-8'),
    ).toString();

    return Container(
      child: Material(
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.close),
                  onPressed: () => Navigator.of(context).pop(),
                ),
              ],
              mainAxisAlignment: MainAxisAlignment.end,
            ),
            Expanded(
              child: WebView(
                initialUrl: source,
                javascriptMode: JavascriptMode.unrestricted,
                onWebViewCreated: (WebViewController controller) {
                  _webViewController = controller;
                  _webViewController.loadUrl(source);
                },
              ),
            ),
          ],
        ),
      ),
      padding: EdgeInsets.all(10.0),
    );
  }

  @override
  void initState() {
    super.initState();
  }
}
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:30] Constructor
W/cr_AwContents(30910): onDetachedFromWindow called when already detached. Ignoring
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:59] isActive: false
I/cr_Ime  (30910): ImeThread is not enabled.
D/EGL_emulation(30910): eglMakeCurrent: 0x8a0f4ca0: ver 2 0 (tinfo 0x8976d190)
W/cr_BindingManager(30910): Cannot call determinedVisibility() - never saw a connection for the pid: 30910
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:59] isActive: true
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation(30910): eglMakeCurrent: 0xb1e05240: ver 2 0 (tinfo 0xb1e03310)
W/cr_BindingManager(30910): Cannot call determinedVisibility() - never saw a connection for the pid: 30910
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:59] isActive: true
D/cr_Ime  (30910): [InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
I/art     (30910): Background sticky concurrent mark sweep GC freed 12(424B) AllocSpace objects, 0(0B) LOS objects, 0% free, 22MB/22MB, paused 10.801ms total 19.097ms
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
I/chromium(30910): [INFO:CONSOLE(9)] "Failed to initialize the editor as the document is not in standards mode. TinyMCE requires standards mode.", source: https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.2.1/tinymce.min.js (9)
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread
W/art     (30910): Attempt to remove non-JNI local reference, dumping thread