问题
I will like to know how to import a new package from third party in flutter and call it in my code?
回答1:
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:
回答2:
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
来源:https://stackoverflow.com/questions/62337407/how-to-import-and-make-use-of-a-package-in-flutter