如何访问pubspec文件中的文件夹包?

huangapple go评论62阅读模式
英文:

How to access folder packages in pubspec file?

问题

我尝试在我的pubspec.yaml中,但它不起作用

packages:
   path: ../package1

结果

如何访问pubspec文件中的文件夹包?

英文:

如何访问pubspec文件中的文件夹包?

I have try in my pubspec.yaml , but it's working

packages:
   path: ../package1

Result

如何访问pubspec文件中的文件夹包?

答案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

huangapple
  • 本文由 发表于 2023年3月1日 15:44:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600790.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定