简体   繁体   English

在 flutter 中使用 import 'dart:html' - 我需要额外的依赖项吗?

[英]using import 'dart:html' in flutter - Do I need additional dependencies?

I came across a websocket example that I would like to use.我遇到了一个我想使用的 websocket 示例。 However it uses import 'dart:html';但是它使用import 'dart:html'; . . When I introduce that in my Flutter project seems like its not being picked up.当我在我的 Flutter 项目中介绍它时,它似乎没有被选中。 Do I need to add additional dependencies to the pubspec.yaml ?我是否需要向pubspec.yaml添加额外的依赖项?

dart:html can't be used in Flutter. dart:html不能在 Flutter 中使用。 It is for browser applications only.它仅适用于浏览器应用程序。

dart:html also only comes with the regular Dart SDK, not with the Dart SDK shipped with Flutter. dart:html也只随普通 Dart SDK 一起提供,而不随 Flutter 附带的 Dart SDK 一起提供。

I know this is an old question but let me drop this answer here.我知道这是一个老问题,但让我把这个答案放在这里。

I've searching for a web crawler/ scraper for Flutter for a while now.我现在已经寻找网络爬虫/刮刀的扑了一段时间。 I've tried to use FlutterWebview and also the html package but no way.Recently i've found a new package for this.我试过使用 FlutterWebview 和 html 包,但没有办法。最近我找到了一个新的包。

The advantage of this package is that it is really cross paltform as expalined:这个包的优点是它真的像解释的那样是跨平台的:

Cross-platform dart:html that works in the browser, Dart VM, and Flutter.在浏览器、Dart VM 和 Flutter 中工作的跨平台 dart:html。

  • Typical use cases are:典型的用例是:

  • Cross-platform application development (eg Flutter mobile and web versions).跨平台应用程序开发(例如 Flutter 移动版和网页版)。 Web crawling and scraping网页抓取和抓取

you can use universal_htm for any scaping / crawling purpose您可以将Universal_htm用于任何转义/爬行目的

Since the merge of Flutter-web into the main Flutter repository, it's no longer possible to directly add imports for web libraries (eg dart:html) in a Flutter project on the main channel when targeting Web, Android and iOS.由于 Flutter-web 合并到主 Flutter 存储库中,当目标为 Web、88156108238388 和 Flutter 时,不再可能在主频道的 Flutter 项目中直接添加 web 库(例如 dart:html)的导入

Use the universal html package which provides extensive support for multiple platforms and web libraries.使用通用的 html package 为多个平台和 web 库提供广泛的支持。

From the root level of your project, command从项目的根级别,命令

1. flutter pub add universal_html 2. import 'package:universal_html/html.dart' as html 1. flutter pub add universal_html 2. import 'package:universal_html/html.dart' as html

This package isn't required to run some web files (eg dart:js).这个 package 不需要运行一些 web 文件(例如 dart:js)。 In my case, I just had to remove the import 'dart:js' import statement.在我的例子中,我只需要删除 import 'dart:js' 导入语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM