How to Solve Unit Testing Errors Not Found 'darthtml' In Flutter Web

Solve Unit Testing Errors: Not Found: ‘dart:html’ In Flutter Web?

Earlier we have been through various articles like How to Handle Error With Bloc Pattern In Flutter. So in this article, we will go through How to Solve Unit Testing Errors: Not Found: ‘dart:html’ In Flutter Web.

How to Solve Unit Testing Errors: Not Found: ‘dart:html’ In Flutter Web??

Why does this error occur: The analyzer produces this diagnostic when an import isn’t needed because none of the names that are imported are referenced within the importing library.

Examples:

The following code produces this diagnostic because nothing defined in

dart:async

is referenced in the library:

import 'dart:async';

void main() {}

From pub.dev/packages/test:

“By default, tests are run in the Dart VM [virtual machine], but you can run them in the browser as well by passing pub run test -p chrome path/to/test.dart. the test will take care of starting the browser and loading the tests, and all the results will be reported on the command line just like for VM tests.

In fact, you can even run tests on both platforms with a single command: pub run test -p “chrome,vm” path/to/test.dart”

To solve my particular problem, we ran the tests using pub run test/print_reports_card_test.dart -p chrome.

Since you are running flutter tests for the web that use the dart:html package you must target the correct platform.

flutter test --platform chrome

User can also try by changing the below codes:

Change import ‘dart:html‘; to import ‘package:http/http.dart‘ as http;

and then change pubspec.yaml files dependencies to

dependencies:
flutter:
sdk: flutter
http:

and click pub get.

Conclusion:

Thank you for being with us on this flutter journey!!

So in this article, we have been through How to Solve Unit Testing Errors: Not Found: ‘dart:html’ In Flutter Web.

Also, don’t miss the article on MergeSemantics Widget.

Keep Learning !!! Keep Fluttering !!!

Do let us know in the comments if you are still confused in flutter!!

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Abhishek Dhanani

Written by Abhishek Dhanani

Abhishek Dhanani, a skilled software developer with 3+ years of experience, masters Dart, JavaScript, TypeScript, and frameworks like Flutter and NodeJS. Proficient in MySQL, Firebase, and cloud platforms AWS and GCP, he delivers innovative digital solutions.

ready to get started?

Fill out the form below and we will be in touch soon!

"*" indicates required fields

✓ Valid number ✕ Invalid number
our share of the limelight

as seen on