如何在 flutter 中调用 class 或另一个包中的函数到另一个包?

How to call class or functions in another packages to another packages in flutter?

我有一个这样的结构项目:

我尝试像 Android 原生(Java 和 Kotlin)那样在 flutter 上实现 modularization,它在 functions 之间发挥 separate 的作用并加快构建过程并简化未来 maintenance.

图中有一个名为“cari_mobile_flutter_main”的root project和两个名为“cari_news”和“cari_network”的flutter包。我设法通过 setting2 packagesroot project 连接起来,将 path 连接到 root project 中的 pubspec.yaml。这样根目录下的lib文件夹就可以从both packages.

access/callclassfunctions

问题是how can each package be connected so that they can call each other's class or function? 例如:“cari_news”可以调用“cari_network”中的classfunctions。它能做到吗?

因为我试图在包之间的 pubspec.yaml 上设置 path 但它不能,并且有这样的错误:

我已经尝试点击右上角的 "packages get" 得到这样的结果:

Running "flutter packages get" in cari_news...
Because cari_news depends on cari_network from path which doesn't exist (could not find package cari_network at "cari_network"), version solving failed. pub get failed (66) Process finished with exit code 66

我尝试将 cari_networkcari_news 链接,以便 cari_news 包可以调用 cari_network 中的 classfunctions包裹。但那不可能。谁能帮帮我?

我的错误,为了回答我的问题,我只是将 ../cari_network 添加到 path 部分。因为 cari_network 包的位置在 root 项目中,而 cari_newsroot 项目中,而 pubspec.yamlcari_news 中包裹。因此,要找到 cari_network 包,只需添加一个 ../