I am getting red lines under my flutter code but the code is perfectly functioning and there is no error

Viewed 4978
8 Answers

I had the same issue, it was very frustrating but was able to solve it.

What worked for me was restoring my Android Studio setting to the default settings by removing the entire ".AndroidStudio4.0" (or whatever version you are using) folder that is usually located in C:\Users\[user name]\.

Then you open Android Studio, select NOT to import any settings, install the Dart and Flutter plugins, and that's it.

It should take about 2 minutes.

Welcome to stack overflow. Looks like a standard package import error.

See link here. https://flutter.dev/docs/development/packages-and-plugins/using-packages

I suggest you try in terminal running three commands

flutter doctor
flutter clean 
flutter pub get

If you see errors at any of these commands, act accordingly.

If no error, I suggest check the contents of your .packages file and pubspec.lock that they list all the dependencies you want to import including Flutter and Dart.

flutter doctor
flutter clean 
flutter pub get

after entering these commands flutter code doesn't compile.

I tried flutter upgrade and now problem got solved.

If you are using VS Code, sometimes restarting your analyzer solves your problem. sometimes flutter clean and then flutter pub get solves. in my case, both are not working. This issue is having with only one project, are projects are still working fine. I think Reinstallng Android Studio and Flutter sdk will solve this

Look at your first import, it should be something like this:

'package:YOURAPPNAME/FadeAnimation.dart'

Also, try to invalidate android studio cache and restart (in file menu)

Use flutter upgrade command this helped me.

After weeks try to figure out the problem and try all the suggestions (not working in my case), I noticed that my project's Flutter SDK path is empty. After I enter the correct path, all the red line disappear instantly!

Steps:

  1. Go to File | Settings | Languages & Frameworks | Flutter.

  2. Flutter SDK path: C:\src\flutter (in my case)

  3. Click Apply

  4. Click OK

The issue is your Fadeanimation file make it fadeanimation the capital word is effect your code.

Related