Flutter autocomplete not working in VSCode for packages - flutter

I moved my whole flutter project to a new folder, everything runs fine. The autocomplete works on the build in files from flutter, like Container, Column, but when I try using a package, like provider, I need to go on the pub.dev page and copy the import, import it manually, then I have to write "Provider.of(context)" manually. In the old project, I used to write Provider, press TAB, and everything would be auto imported and the VSCode would auto complete everything related to provider, not just bult in files. Whan should I do?

You must make sure that your dependencies for plugins are mentioned under dependencies: section, not under dev_dependencies: section like following:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.7
firebase_auth: ^0.16.1
fluttertoast: ^7.0.2

I was getting the same issue and fixed it by changing the flutter channel.
The problem seems to be with the dart that ships with the flutter code.
If you are still facing this issue. Then try to change your channel
flutter channel ...
And then try
flutter upgrade
This will pull the dart version again and hopefully fix the import issue.

Try to restart VS Code, worked for me.

Related

Why is flutter not detecting locally made packages?

I have been assisting with building an app with Flutter.
My senior shared the repo with me, however when I cloned it, all of the import packages had a 'uri not found' error.
I ran flutter pub get, and all of the external packages work. However the locally made packages, such as 'package:projectname/utils/utils.dart' still have an error.
How can I fix this? Preferably the fix is in my enviroment. I do not want to change any of the code since it works for him. TIA.
pubspec.yaml
dependencies:
flutter:
sdk: flutter
stackoverflow_pkg:
path: C:\Users\xxxxx\flutter_projects\stackoverflow\stackoverflow_pkg
code:
import 'package:stackoverflow_pkg/stackoverflow_pkg.dart';

How to set dependencies in the right way in pubspec.yaml in Flutter

Here are a few dependency examples from my pubspec.yaml file in my Flutter project.
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.4
firebase_core_web: ^0.2.1
firebase_crashlytics: "^0.2.4"
firebase_analytics: "^6.3.0"
I just followed installation guidelines when installing each of them. As seen, some dependencies have the version number in "..." while others don't.
It seems to be working in both ways but I wonder what the right way of doing it. Should I always put the version number into "..." ?
The best way to do this is:
flutter pub add form_field_validator
where "form_field_validator" is the name of dependency
Have a look why it is a best method:
It automatically adjusts all of the the dependencies
So you don't get "version solving failed" error like this showing below:
Because flutter_bloc: 0.21.0 depends on provider: ^3.0.0 and no versions of flutter_bloc match: >0.21.0 <0.22.0, flutter_bloc: ^0.21.0 requires provider: ^3.0.0. So, because it tells_me that it depends on both provider: ^4.1.2 and flutter_bloc: ^0.21.0, version solving failed.
https://pub.dev/packages/form_field_validator/install
has both methods copy and paste the given command in your project directory
See below image:
Thank you I hope it clears everything, happy coding!
You can provide version numbers with and without quotes. The quotes are used for providing range constraints on dependencies like this:
dependencies:
url_launcher: '>=5.4.0 <6.0.0'
So that's why both options work. If you are not using ranges you can omit the quotes but it comes down to personal/team preference. See the Flutter documentation for more information on using packages.
If you don't put any number or version number, it takes the latest version.
When creating new projects, it will work good. However if you are re-using codes from other projects, you might want to use the exact same version of the dependencies, hence you define them.

How to resolve Firebase AdMob Integration problem

I am trying to add AdMob ads to my Flutter app. For that, I tried using firebase_admob (^0.9.3+2) plugin but it's not working for me, it stuck at build.apk.
I am getting the output as :
Note: /home/abhishek/dev/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_admob-0.9.3+2/android/src/main/java/io/flutter/plugins/firebaseadmob/AdRequestBuilderFactory.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
My dependency in pubspec.yml are :
dependencies:
flutter:
sdk: flutter
meta: ^1.1.8
platform: ^2.2.1
firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_admob: ^0.9.3+2
Where am I doing wrong?
See if you can remove firebase_core: ^0.4.0+9 then exec flutter clean
Not sure if it is related or not, but I'm having problems adding dependencies:
Error: Could not resolve the package 'google_sign_in' in 'package:google_sign_in/google_sign_in.dart'.
lib/authsvc.dart:7:8: Error: Not found: 'package:google_sign_in/google_sign_in.dart'
import 'package:google_sign_in/google_sign_in.dart';
I'm able to add the dependency in the pubspec.yaml file, run 'pub get' and it says that it downloads fine. No errors are reported in the editor (i.e. it recognizes the new commands and doesn't flag them). However, when I try to compile/build it, I get the above error message. 'Pub get' worked fine until I upgraded to the latest version of Flutter (v. 1.17.3) before I believe I was on (v. 1.17.0).
To fix it, I hardcoded the path in the Dart_Packages.xml file.
(I'm not looking to troubleshoot further, just adding this in case it helps the developers identify the problem). Thanks!

flutter has a problem with redux dependencies

i have a problem to run my flutter app, it seems flutter doesn't recognize it. i tried to connect to internet while running the project but the problem remains the same, here is the error message:
and here is the code where i inserted the dependency :
dependencies:
redux: ^4.0.0
flutter_redux: ^0.6.0
Your package name is likely also redux according to this Github issue. You'll have to change your package name to something other than redux and you should be able to flutter pub get.
this error was caused by the fact that i named my app REDUX, i changed it and it works now.

Target of URI doesn't exist 'package:english_words/english_words.dart'

I'm learning to use Flutter using Android Studio. I'm going through step by step doc provided by Flutter. At Step:2 Use an external package I'm getting issue importing the english_words package. I have properly added the package in pubspec.yaml and clicked Packages Get which added the dependency but at the time of importing the package in lib/main.dart it is saying
Target of URI doesn't exist
'package:english_words/english_words.dart'.
I have seen many questions on StackOverflow but none of them helped me. Please help!
For some packages, once you do all the process described by the other answers to this question, you have to close the Android project and open it again. As well as the emulator.
Some packages need the restart, others do not need it.
After adding the package in the pubspec.yaml file, you need to execute the command flutter packages get or click on "Packages Get" in the action ribbon at the top of pubspec.yaml file.
Then the dependency and any transitive dependency will be added to the .packages file.
Check this:
https://flutter.io/using-packages/
Solution (For VSCode):
Run flutter packages get in pubspec.yml
Restart VSCode
I had the same issue and went about it like listed below and it worked.
1. Add the package
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
**english_words: ^3.1.5**
Save the pubspec.yaml file
go to your terminal and run 'flutter packages get'
4.Close your simulator and rebuild your cradle
Run the main.dart again and it should remove the error.
This is what worked for me, all the best.
Make sure that english_words is on the base-line with flutter:
Took me a lot of time, but in summary, just save the file pubspec.yaml will do. The command flutter pub get will be ran once u save it, then u can import the package.
There is no need to restart ur editor etc.
My solution was to add the "english_words: ^3.1.5" the version at the moment that I write this, under the "dependencies:" and before the "Flutter:" argument, without the "+" sign.
Hope that helps
I used this and it worked for me... without + sign and version in double quote ""..
english_words: "^3.1.5"
Make Sure that the alignment of english_words is correct inside your pubspec.yaml as it's "space sensitive" :
dependencies:
english_words: ^3.1.5 //two spaces
also never align it using tabs, I don't know why but it never works, and don't use + sign
There are so many methods to solve this issue, most of them will get solved on the second step,if not please try third method also it will work.
Run flutter packages get in pubsec.yaml file (if you are using VS Code it will be easier).
Restart your IDE.
Check it now, mostly it will work. If not try third step.
you have to repair pub caches
flutter packages pub cache repair
I hope it will work. if all methods are not working try to re install flutter.
my friend solution is so simple only add this code line in file pubspec.yaml
english_words: ^3.1.0
like this
dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
english_words: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
it would work perfectly:)
I faced the same issue but I managed to solve it using the steps below:
add the package as an example english_words: ^3.1.0" in 'pubspec.yaml file.
save file or press ctrl+s
//the Output Console will appear this message
[app name] flutter packages get.
Running "flutter pub get" in first_app..., 2.4s
exit code 0.).
3. check main.dart file, the error will be removed.
For me nothing worked. Things resolved only after
Flutter upgrade
in pubsec.yaml file
For those who are still experiencing this problem, it took me hours to figure out what was wrong. Basically, if all the other answers don't work:
Open the test/.packages file on whatever IDE you are using
Locate the package that is not working and go to that directory on your computer.
Delete the whole package. In my case it was the whole english_words package folder.
In the pubspec.lock and .packages file, delete all instances of that package.
run pub get
In the docs of https://flutter.dev/docs/get-started/codelab there is the following code:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
+ english_words: ^3.1.5
The thing which is causing the error is "+ sign". I just removed it and all worked fine for me.
Delete the plus sign "+" in front of english_words (if you have one)
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^3.1.5
I got the same issue.
It is observed only in version 4.0.0 .For lower versions there is no problem.
So here is what you can do to solve this:
Download code for the dependency from :
https://github.com/filiph/english_words
Unzip it Rename it to
english_words-4.0.0
Copy this folder.
Now go to flutter's SDK folder and navigate to
.pub-cache\hosted\pub.dartlang.org
and paste the folder english_words-4.0.0 here. Add dependency in pubspec.yaml file. Now run flutter pub get command.
You are good to go.
Note : How to find the path of Flutter SDK
All you need to do is to restart IDE(Android studio or VSCode)
Having this error message:
Error: Cannot run with sound null safety, because the following
dependencies don't support null safety:
package:english_words
I had to change this dependency english_words: ^3.1.5 to the latest version english_words: ^4.0.0 and make "pub get":
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^4.0.0
provider: ^6.0.0
in your pubspec.yaml file, instead of:
english_words: ^4.0.0
try:
english_words: '4.0.0'
it worked for me