英文:
How to access folder packages in pubspec file?
问题
我尝试在我的pubspec.yaml中,但它不起作用
packages:
path: ../package1
结果
答案1
得分: 2
你可以将它添加到 dependency
部分并指定一个名称。
dependencies:
my_local_package:
path: ../package1
然后可以这样使用它:
import 'package:my_local_package/package1.dart';
英文:
You can add it in the dependency
part and specify a name.
dependencies:
my_local_package:
path: ../package1
And use it as
import 'package:my_local_package/package1.dart';
答案2
得分: 1
你可以使用两种方式,一种是将你的包上传到GitHub并通过它访问,另一种是本地方式。以下是相关的代码:
文件路径依赖
Flutter应用程序可以使用文件系统路径依赖于一个包。路径可以是相对路径或绝对路径。相对路径是相对于包含pubspec.yaml文件的目录进行评估的。例如,要依赖于一个位于与应用程序相邻目录中的包packageA,可以使用以下语法:
dependencies:
packageA:
path: ../packageA/
从Git获取
你也可以依赖于存储在Git仓库中的包。如果包位于仓库的根目录,可以使用以下语法:
dependencies:
packageA:
git:
url: https://github.com/flutter/packageA.git
获取更多信息,可以参考这个链接:https://docs.flutter.dev/development/packages-and-plugins/using-packages
英文:
you can use two ways,upload your package to github and access via it,or local..here are the code for it
Path dependency
A Flutter app can depend on a package using a file system path: dependency. The path can be either relative or absolute. Relative paths are evaluated relative to the directory containing pubspec.yaml. For example, to depend on a package, packageA, located in a directory next to the app, use the following syntax:
dependencies:
packageA:
path: ../packageA/
from git
You can also depend on a package stored in a Git repository. If the package is located at the root of the repo, use the following syntax:
dependencies:
packageA:
git:
url: https://github.com/flutter/packageA.git
for more info get an idea from this https://docs.flutter.dev/development/packages-and-plugins/using-packages
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论