flutterdartvisual-studio-code

Why can't I import the package that I just installed?


I recently started learning flutter/dart and I have a Problem that i couldn't solve. I've read in the official flutter documentation that you have to follow these three steps to install a package in flutter:

  1. Add the package (in my case: 'english_words: ^3.1.5') to the dependencies in the pubspec.yaml file.
  2. Run the 'flutter pub get' command to include the package to the '.packages' file.
  3. Add import 'yourpackagename' (in my case: 'package:english_words/english_words.dart') to the main.dart file.

My problem is though that VS marks it as an error if I try to do step 3: Target of the URI doesn't exist

Any ideas what I could do? I've installed the flutter and dart extensions for VS Code and also tried to restart the program but nothing worked.


Solution

  • try running

    flutter clean
    

    if it is still not working, run:

    flutter clean pub cache