How to add a package in the android studio - flutter? - flutter

I started fluttering a few days ago. I want to add "font awesome" to my project, but I can't. I searched but could not find the right answer. I finally got this guide, but it doesn't work either.
Adding a package dependency to an app
To add the package, css_colors, to an app:
Depend on it
Open the pubspec.yaml file located inside the app folder, and add css_colors: under dependencies.
Install it
From the terminal: Run flutter pub get.
OR
From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec.yaml.
Import it
Add a corresponding import statement in the Dart code.
4. Stop and restart the app, if necessary
If the package brings platform-specific code (Kotlin/Java for Android, Swift/Objective-C for iOS), that code must be built into your app. Hot reload and hot restart only update the Dart code, so a full restart of the app might be required to avoid errors like MissingPluginException when using the package.

In the dependencies: section of your pubspec.yaml, add the following line:
dependencies:
font_awesome_flutter:

Look here https://pub.dev/packages/font_awesome_flutter/install
It contain examples and instructions.
Steps also the same:
add the package name to dependencies section. It very important to keep the correct number of spaces in every line of pubspec.yaml, it has very sensitive format
in your case:
dependencies:
font_awesome_flutter: ^8.10.0
Click "Packeges get" in top right corner
Import the package into your dart code
in your case:
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Now your can use it in Icon widget
Icon(
FontAwesomeIcons.mars,
size:80.0)

Related

How to import and make use of a package in flutter?

I will like to know how to import a new package from third party in flutter and call it in my code?
You can find a lot of packages on Pub.dev.
To import it just open any package and navigate to the Installing Tab.
Then you just need to copy this sentence to your pubspec.yaml file.
Paste line under dependencies in pubspec.yaml. Note that spaces is very important so make it start just under flutter: when pasting.
Save changes in pubspec.yaml and it will install the packages automatically. If it doesn't install run flutter pub get from command line to install the package manually.
Lastly do not forget to import the library at the top of the file by using the line provided here:
Put the library in pubspec.yaml, then run flutter packages get in your IDE terminal.
Ex:
I'm using toast package, so I will define this in pubspec.yaml
toast: ^0.1.5

packages get not fetching .packages for English Words with proper pubspec.yaml

for context I am currently following this exercise provided by flutter dev: https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1/#3
I use android studio on a Windows 10 profesional.
I have seen this issue across many different areas and I am continually unable to get the English_Words package to upload. I had even uploaded the file directly the .packages and had the import work, however, the functions and classes do not validate
This is the import from main.dart
This is the pubspec.yaml, with the dependency properly spelled out
I had navigated and manually put in the english_words dependency. However, then the methods would not engage, even when the import worked. Furthermore, when I did ''' -flutter packages get ''', the file was removed, even with the .yaml dependency spelled out.
I have done lots of the recommended things:
-flutter doctor
-deleting the pubspec.lock and upgrading/getting packages
-shutting down the virtualization and android studio
cupertino icon and english words must have have a spacing of 2 just like flutter
ex:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words:^3.1.5
this is a YAML file so spacing have a special meaning. just correct it as i did in example enjoy.

how to "Migrate the plugin to the pubspec platforms manifest"

I have created a new flutter app and after adding cloud_firestore 0.13.0+1 it will not compile. No errors it just stops and removes the row of compile icons. An Analysing spinner revolves forever.
In pub.dev it says to "Migrate the plugin to the pubspec platforms manifest." unfortunately I have been unable to find out where that is or how to do it in the documents or StackOverflow. Please help.
According to documentation, the plugins you required need to be added under dependencies in to a pubsec.yaml file located in the root of your project.
dependencies:
cloud_firestore: ^0.13.0+1
After your plugins are added to pubsec.yaml, you can make use of those dependencies in your code by using imports.
import 'package:cloud_firestore/cloud_firestore.dart';

Flutter web cannot use packages from mobile project

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.
Then right now I want to convert the project to flutter_web. Here are the steps that I did:
clone github web flutter
I run the command "flutter packages pub global activate webdev"
Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)
Here is the contents of pubspec.yaml on the web flutter project:
name: flutter_web.examples.hello_world
environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'
dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1
dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web_ui
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web
When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using
 import 'package: flutter / material.dart';
So that makes my pubspec error. Because the code should be replaced with
import 'package: flutter_web / material.dart';
Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).
The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.
What I want to ask, is there a more elegant and simple way?
Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.
Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.
First you will have to enable the flutter-web using flutter config --enable-web.
Then you will have to run flutter create .

how to add external package to flutter with visual studio code

the doc reference android studio, but I'm using Visual Studio Code, so how do I do this?
"While viewing the pubspec in Android Studio’s editor view, click Packages get upper right."
in pubspec.yaml I added "english_words: ^3.1.0", and I ran 'flutter packages get' from the command palette but it's not working.
make sure you are saving the file before running flutter packages get
I was having error on mine too. This was my initial code
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
and I got this error
"Error on line 25, column 5 of pubspec.yaml: A dependency may only have one source."
so I adjusted my indentation like so
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
And it worked just fined
HOW TO ADD EXTERNAL PACKAGE TO DART AND FLUTTER WITH VISUAL STUDIO CODE
The final solution to this problem is here
you will get the latest version of whatever package you are looking for
Forget going to the pub.dev to search for your packages and copy the dependency
text.
THE SOLUTION IS:
Install the "pubspec assist" by Jeroen Meijer in the extension menu.
Open the pubspec.yaml file in the vs code.
Simply open the Command Palette (by default, Ctrl+Shift+P on Windows, ⌘+Shift+P
on Mac) and search for "Pubspec Assist" and press ENTER.
Then search for the required package with their names. It will automatically add
the dependencies to the pubspec.yaml file. After that save the file using
Ctrl+S.
Get ready to import the package in the main file.