Flutter 开发插件

Flutter 插件

1
flutter create -t plugin flutter_plugin_demo

1 原生插件(调用 java 或其它语言)

  1. 通过 android studio 创建, 包含 java 和 ios 选择 flutter plugin , 纯 dart 选择 flutter package ,

  2. 在 pubspec.yaml 中声明兼容平台

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
      plugin:
        platforms:
          android:
            package: com.example.flutter_plugin_test
            pluginClass: FlutterPluginTestPlugin
          ios:
            pluginClass: FlutterPluginTestPlugin
          macos:
            pluginClass: FlutterPluginTestPlugin
          web:
            pluginClass: FlutterPluginTestPlugin
            fileName: flutter_plugin_test.dart
    
  3. 在 项目名.dart 中创建方法

image-20200408103156402

  1. 调用该方法

image-20200408103302373

  1. 进入安卓底层目录, 使用 java 实现数据

image-20200408103349386

参考

https://book.flutterchina.club/chapter12/develop_plugin.html

2 纯 dart 库

参考

https://book.flutterchina.club/chapter12/develop_package.html

  1. 创建 flutter package
  2. 修改 pubspec.yaml 包相关信息, 输入 flutter pub publish --dry-run 测试是否合格

发布见 3 搭建私有仓库

3 搭建私有仓库

  1. 安装 dart
1
2
brew tap dart-lang/dart
brew install dart
  1. 搭建环境
1
2
3
4
git clone https://github.com/dart-lang/pub_server.git
cd pub_server
pub get
dart example/example.dart -d /tmp/package-db
  1. 将项目发布
1
flutter packages pub publish --server=http://localhost:8080
  1. 谷歌验证

image-20200408112444945

在浏览器中打开地址, 登录谷歌账户即可

image-20200408112514209

参考:

官方提供快速搭建仓库 https://github.com/dart-archive/pub_server

如何上传插件 https://ejin66.github.io/2019/04/11/flutter_private_pub.html

Licensed under CC BY-NC-SA 4.0
本文阅读量 次, 总访问量 ,总访客数
Built with Hugo .   Theme Stack designed by Jimmy