Skip to content

WangYng/better_flutter_pugin_creator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

better_flutter_plugin_creator

创建 flutter plugin 时, 同时创建 flutter plugin 的Flutter端函数, Android端函数 与 iOS端函数

功能:

  • 自动生成template.py中定义的Flutter端Dart函数
  • 自动生成Dart函数对应的Android端Java函数
  • 自动生成Dart函数对应的iOS端Objective-C函数

用法:

  1. 创建 env.py, 填入必须的参数
import os.path

# 插件名称
plugin_name = 'better_plugin'

# 插件作者
plugin_author = '汪洋'

# 插件描述
plugin_description = 'A better plugin.'

# 插件标识
plugin_org = 'io.github.wangyng'

# 插件包名
plugin_package = plugin_org + '.' + plugin_name

# 根地址
root_dir = '/Users/wangyang/Desktop'

# 项目地址
project_dir = os.path.join(root_dir, plugin_name)

# flutter命令地址
flutter = '/Users/wangyang/library/flutter2/bin/flutter'

# 覆盖 plugin.dart Plugin.java Plugin.h.m 的代码
cover_plugin_file_code = True
  1. 修改 template.py, 替换成需要生成的dart函数
dart_template = \
'''
Stream test1ResultStream;

Future<void> test1();

Future<String> test2(String p1);

Future<int> test3(String p1, int p2);

Future<bool> test4(String p1, int p2, bool p3);

Future<double> test5(String p1, int p2, bool p3, double p4);

Future<Map> test6(String p1, int p2, bool p3, double p4, Map p5);

Future<List> test7(String p1, int p2, bool p3, double p4, Map p5, List p6);
'''
  1. 使用pip添加必须的第三方库依赖
pip3 install GitPython gitdb setuptools smmap
  1. 运行脚本, 几秒后生成新的Flutter插件
python3 main.py
  1. 填入Android端iOS端模板函数中的需要实现的代码
  • 需要填入代码的位置已经加入了以下注释
// TODO
  1. 更新模板函数
  • 修改template.py文件
  • 修改env.py文件,设置是否覆盖 plugin 文件
  • 重新执行本脚本,会自动覆盖 api 文件,并根据设置自动覆盖 plugin 文件

About

Create flutter plugin by template.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages