如何在本地使用Flutter插件?

8
假设我们使用Flutter创建了一个名为 flutter_local_plugin 的插件。如何将其放在 Flutter 项目 flutter_some_application 中并访问它? 有一个问题(how to use local flutter package in another flutter application?),但是接受的答案没有关于实际文件迁移的解释。
  • 我们只需要将插件放置在 flutter_some_application 中,不需要来自包项目的任何 example
  • 您将 .kt 和 .dart 文件放在哪里,以及如何将所有内容链接在一起?

似乎没有指南可以达到这个目的。

1个回答

0
我使用 Android Studio 4.0 创建了一个名为 printer 的 Flutter 插件。 我们可以在 pubspec.yaml 中找到相关提示:
  printer:
    # When depending on this package from a real application you should use:
    #   printer: ^x.y.z
    # See https://dart.dev/tools/pub/dependencies#version-constraints
    # The example app is bundled with the plugin so we use a path dependency on
    # the parent directory to use the current plugin's version. 
    path: ../

然后我在另一个Flutter项目中本地使用打印机:

  printer:
    path: ../printer/

在执行 pub get 命令后,我发现打印机被自动添加到 .flutter-plugins 和 .flutter-plugins-dependencies 中。


这个答案没有解释并不是很有意义。我制作了一个插件,但是../路径无法工作。 - Alberto M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接