-4

How can i solve this error and please tell me why do we get this , the given below is my main.dart file

enter image description here

Manishyadav
  • 1,361
  • 1
  • 8
  • 26
  • 1
    You cannot use `dart:html` unless your target platform is a web application. It looks lik you are trying to make a Flutter application and run it as an Android application on an Android phone. – julemand101 Jan 09 '22 at 14:01
  • @julemand101 Yes, I was trying to make a mobile application and not web, – Manishyadav Jan 09 '22 at 14:11
  • Ok, can you show us the content of `main.dart`? Also, please don't post screenshots unless it is the only way to communicate your problem. You should post your error and code as text. – julemand101 Jan 09 '22 at 14:12
  • @julemand101 I got your point and thanks for your advice and time – Manishyadav Jan 09 '22 at 14:18
  • Where in your project have you inserted the line `import 'dart:html'`? – julemand101 Jan 09 '22 at 14:19
  • How do you get to know that i have inserted it into gradel ,please can you point it out... – Manishyadav Jan 09 '22 at 14:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240891/discussion-between-julemand101-and-manishyadav). – julemand101 Jan 09 '22 at 14:23

2 Answers2

3

As described on the front-page of the API documentation for Dart: https://api.dart.dev

  • dart:html: DOM manipulation for web apps (available only to web apps).
  • dart:io: I/O for non-web apps.

So dart:html can only be used if your target platform is web (so Dart code compiled to JavaScript). In your case, you are trying to make an Android application which runs native on your phone. You can therefore not use dart:html but should instead look into dart:io (which are not available for web-applications) if you need access to IO operations.

julemand101
  • 28,470
  • 5
  • 52
  • 48
2

I deleted import 'dart:html'; line. And its ok. Also, don't forget to delete in other .dart file such as class or widgets.

Bunyamin
  • 21
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '22 at 12:38
  • Deleting the `import 'dart:html'` line helped me. I'm not sure how it got there – Matthew Peterson May 20 '23 at 19:28