'Error: Not found: 'dart:js' import 'dart:js';

I am creating a PopupMenuButton() in the AppBar section.
This is my file:

import 'dart:js';
import 'package:bfdi_app/settings.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class ProfilePage extends StatefulWidget {

  @override
  _ProfilePageState createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'App_Name',
          ),
        actions: <Widget>[
            PopupMenuButton(
              icon: Icon(Icons.settings),
              onSelected:(value){
                if(value==0){
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context)=>SettingPage())
                  );
                }
              },
              itemBuilder: (context) => [
                    PopupMenuItem(
                      child: Text("Settings"),
                      value:0,
               ],
            ),
          ],
       ),
      }

Now I am facing an error in Console Log:

Compiler message:
lib/Pages/addPost.dart:1:8: Error: Not found: 'dart:js'
import 'dart:js';
       ^
lib/Profile/profile.dart:1:8: Error: Not found: 'dart:js'
import 'dart:js';
       ^

I have already added the dependency dart:js, but still getting the same error. Error: enter image description here



Solution 1:[1]

EDIT: I have switched to the master channel and all working fine. Although I don't see any requirement of dart.js in your current code. so you can remove that too


ORIGINAL ANSWER: I believe you are using stable channel so try to switch to beta channel. Open your terminal and run,

$ flutter channel beta

Solution 2:[2]

Go to your flutter installed directory/.pub-cache/hosted/pub.dartlang.org/js-0.6.3-nullsafety.1/lib/js.dart

Delete or comment this line:

export 'dart:js' show allowInterop, allowInteropCaptureThis;

Then try again

Solution 3:[3]

I just del import 'package:js'. it works for me.

Solution 4:[4]

Quoting pub.dev:

  1. Depend on it
    Add this to your package's pubspec.yaml file:

    dependencies:
      js: ^0.6.2
    
  2. Install it
    You can install packages from the command line:

    with pub:

    $ pub get
    

    with flutter:

    $ flutter pub get
    

    Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

  3. Import it Now in your Dart code, you can use:

    import 'package:js/js.dart';
    

Solution 5:[5]

Sounds like an import issue as soon as you are trying to compile for a native application.

Try searching for and delte the incorrect dart:js import (import 'dart:js';).

Have a look at this GitHub issue #70373

Solution 6:[6]

Try using the js package: https://pub.dev/packages/js#-installing-tab-
You should try to use package:js instead of dart:js

Solution 7:[7]

Actually mine was solved with just a system restart and a "flutter clean" command. (yes I am using beta channel) But weird thing was the files were existed already but the dependencies somehow couldn't read from the dart packages.

Solution 8:[8]

in my case just flutter clean solved the issue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Aqeel
Solution 3 ????? ????????
Solution 4 tresf
Solution 5 creep3007
Solution 6 Arhaam Patvi
Solution 7 Regetix
Solution 8 Benderradji Khireddine