简体   繁体   中英

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

I came across a websocket example that I would like to use. However it uses import 'dart:html'; . When I introduce that in my Flutter project seems like its not being picked up. Do I need to add additional dependencies to the pubspec.yaml ?

dart:html can't be used in 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.

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.

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.

  • Typical use cases are:

  • Cross-platform application development (eg Flutter mobile and web versions). Web crawling and scraping

you can use universal_htm for any scaping / crawling purpose

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.

Use the universal html package which provides extensive support for multiple platforms and web libraries.

From the root level of your project, command

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). In my case, I just had to remove the import 'dart:js' import statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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