///递归式读取 fffa电池电量
void recursiveReadFFFA()async{
Future.delayed(Duration(seconds: 1),()async{
List<int>? res;
///一定要try catch,否则一旦有异常,递归就会终止
try{
res = await observeCharacteristic?.read();
}catch(e){
print('BlueToothLogic.recursiveReadFFFA e:${e.toString()}');
}
if(res?[0] != null){
isCharging.value = res![0];
}
if(res?[2] != null){
batteryLevel.value = res![2];
}
int? highHex = res?[3];
int? lowHex = res?[4];
if(highHex != null && lowHex != null){
timeStarted.value = highHex* 255 + lowHex;
fffaList.value = res ?? [];
}
recursiveReadFFFA();
});
}
Flutter 打包 android端 apk 【终端生成签名文件上传Google Play】
https://juejin.cn/post/6944000831465193480
网友评论