如何在本地使用flutter插件?

Den*_*nko 8 flutter flutter-plugin

假设我们已经创建了一个 flutter 插件。命名为flutter_local_plugin。我们如何将其放入flutter项目flutter_some_application中并访问它?这里有一个问题(how to use local flutter package in another flutter application?),但接受的答案对实际文件迁移有 0 个解释。

  • 我们只需要将该插件放置在flutter_some_application中,不需要包项目中的任何示例。
  • 您将 .kt 和 .dart 文件放置在哪里,以及如何将所有这些文件链接在一起?

似乎没有关于如何实现这一目标的指南。

fat*_*gle 1

我用Android Studio 4.0创建了一个flutter插件,名字是printer。我们可以在 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: ../
Run Code Online (Sandbox Code Playgroud)

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

  printer:
    path: ../printer/
Run Code Online (Sandbox Code Playgroud)

pub get 后,我​​发现打印机自动添加到 .flutter-plugins 和 .flutter-plugins-dependency 中。