如何在 Flutter 和 JavaScript 之间创建通信桥?

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我在之前的一篇"},{"type":"link","attrs":{"href":"https:\/\/medium.com\/free-code-camp\/how-to-build-cross-origin-communication-bridges-in-ios-and-andriod-7baef82b3f02?ref=hackernoon.com","title":"","type":null},"content":[{"type":"text","text":"文章"}]},{"type":"text","text":"中解释了如何在Android和iOS中创建通信桥,作为后续,我认为解释一下如何在Flutter中创建通信桥也是一个不错的想法。虽然这可能看起来是一件很简单的事情,但你很快就会意识到,要使这个功能正常工作需要一些工作。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先,重要的是意识到(在撰写本文时)Flutter还"},{"type":"text","marks":[{"type":"strong"}],"text":"没有"},{"type":"text","text":"内置对嵌入式WebView的支持。这意味着,在Kotlin或Swift中的本地应用程序中你可以实例化一个WebView组件,而在Flutter中你不能直接将WebView组件添加到你的应用程序中。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在创建一个新的Flutter项目后,我们需要使用"},{"type":"link","attrs":{"href":"https:\/\/pub.dev\/packages\/webview_flutter?ref=hackernoon.com","title":"","type":null},"content":[{"type":"text","text":"webview_flutter包"}]},{"type":"text","text":"来使得能够使用WebView。我们会向pubspec.yaml文件中添加依赖:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"dependencies:\n flutter:\n sdk: flutter\n webview_flutter: ^1.0.7"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然后,我们需要运行"},{"type":"text","marks":[{"type":"strong"}],"text":"Pub get"},{"type":"text","text":"或者在终端中:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"flutter pub get"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 然后,我们需要在main.dart文件中导入这个包:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"import 'package:webview_flutter\/webview_flutter.dart';"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章