flutter ume custom plugin
flutter ume 自定义插件
flutter create -t package flutter_ume_kit_analysis
创建一个插件包修改插件包的
pubspec.yaml
,添加依赖1
2dependencies:
flutter_ume: '>=0.2.0 <0.3.0'
创建插件配置,实现
Pluggable
虚类1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28import 'package:flutter_ume/flutter_ume.dart';
class Analysis implements Pluggable {
Analysis({Key? key});
@override
Widget buildWidget(BuildContext? context) {
return Container(
color: Colors.white,
width: 100,
height: 100,
child: const Center(child: Text('TODO')),
);
} // 返回插件面板
@override
String get name => 'Analysis'; // 插件名称
@override
String get displayName => 'Analysis';
@override
void onTrigger() {} // 点击插件面板图标时调用
@override
ImageProvider<Object> get iconImageProvider =>
MemoryImage(base64Decode(iconData)); // 插件图标
}在工程中引入自定义插件
修改
pubspec.yaml
,添加依赖1
2
3dev_dependencies:
flutter_ume_kit_analysis:
path: path/to/flutter_ume_kit_analysis执行
flutter pub get
引入包
1
import 'package:flutter_ume_kit_analysis/flutter_ume_kit_analysis.dart';
在工程中注册插件
1
2
3
4
5
6
7if (kDebugMode) {
PluginManager.instance
..register(Analysis());
runApp(injectUMEWidget(child: MyApp(), enable: true));
} else {
runApp(MyApp());
}运行代码
Author: qomg
License: 本博客所有文章除特别声明外,均采用许可协议 CC-BY-NC-4.0 转载请注明出处!