45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
|
|
import 'package:flutter/services.dart';
|
|
|
|
///原生交互配置
|
|
class NativeInteractionConfig{
|
|
static String methodSendChannel = 'starLockFlutterSend';
|
|
static String receiveEventChannel = 'starLockFlutterReceive';
|
|
}
|
|
|
|
///原生交互flutter向原生发送消息
|
|
typedef BlockBlueStatus = void Function(String status);
|
|
class NativeInteractionTool{
|
|
var sendChannel = MethodChannel(NativeInteractionConfig.methodSendChannel);
|
|
var receiveChannel = MethodChannel(NativeInteractionConfig.receiveEventChannel);
|
|
|
|
///加载原生分享
|
|
loadNativeShare({required String shareText}){
|
|
sendChannel.invokeMethod('loadNativeShare', {'shareText':shareText});
|
|
}
|
|
|
|
///获取设备蓝牙状态
|
|
sendGetBlueStatus(){
|
|
sendChannel.invokeMethod('sendGetBlueStatus');
|
|
}
|
|
|
|
///获取设备蓝牙是否打开
|
|
receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus){
|
|
receiveChannel.setMethodCallHandler((MethodCall call) async {
|
|
print('收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}');
|
|
switch (call.method) {
|
|
case 'getBlueStatus':
|
|
// 获取设备蓝牙开启/关闭状态
|
|
final String message = call.arguments;
|
|
blockBlueStatus(message);
|
|
print('收到原生发送的信息getBlueStatus: $message');
|
|
break;
|
|
default:
|
|
throw MissingPluginException();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|