该插件支持双屏安卓设备,主副屏使用Flutter进行绘制,使用channel实现双屏间的通信交互。
在pubspec.yaml文件中进行引用:
dependencies:
flutter_subscreen_plugin: ^1.0.0
使用flutter进行主副屏的绘制,以及使用封装能力进行主副屏交互通信:
void main() {
var defaultRouteName = window.defaultRouteName;
if ("subMain" == defaultRouteName) {
viceScreenMain();
} else {
defaultMain();
}
}
//主屏ui
void defaultMain() {
runApp(MainApp());
}
//副屏ui
void viceScreenMain() {
runApp(SubApp());
}
SubScreenPlugin.sendMsgToViceScreen("data", params: {"params": "123"});
SubScreenPlugin.viceStream.listen((event) {
print(event.arguments.toString());
});
SubScreenPlugin.isMultipleScreen((result) {
print("是否支持双屏:$result");
});
SubScreenPlugin.checkOverlayPermission((result) {
print("是否支持 overlay:$result");
});
SubScreenPlugin.requestOverlayPermission();
SubScreenPlugin.doubleScreenShow(); //开启
SubScreenPlugin.doubleScreenCancel(); //关闭
android -> values -> attrs.xml 添加配置
<!-- 是否在初始化时自动显示副屏 -->
<bool name="autoShowSubScreenWhenInit">true</bool>
android -> mainActivity -> onCreate 方法添加
FlutterSubscreenPlugin.tripPlugins = arrayListOf(...具体的三方库名...)
例如:
FlutterSubscreenPlugin.tripPlugins = arrayListOf(VideoPlayerPlugin())
//VideoPlayerPlugin由video-player三方插件提供
以上使用方式,完整样例可参照插件中的example