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

蓝咒 提交于 2021-02-11 15:40:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!