flutter自学二

外部包使用

方法:

pubspec文件管理Flutter应用程序的assets(资源,如图片、package等)。

1、在pubspec.yaml中,将english_words(3.1.0或更高版本)添加到依赖项列表,如下面高亮显示的行:

dependencies:
  cupertino_icons: ^0.1.0
  english_words: ^3.1.0

2、点击pubspec.yaml右上方菜单栏的pub get文字,相当于android studio改完build.gradle文件后的sync文字效果,同步下载依赖的库,或者:terminal中运行flutter pub get

3、然后就可以使用引入的库了,到你的dart中,import会有智能提示,输入你的包即可

4、运行的时候遇到的问题:

解决:

Edit Configurations --> Add Additional Run args --> --no-sound-null-safety

猜你喜欢

转载自blog.csdn.net/qwildwolf/article/details/117565331