Implementation
Stream<List<BLEDevice>> get bondedList async* {
List<BLEDevice> bondList = [];
Map<Object?, Object?> list = await _methodChannel.invokeMethod('bond_list');
list.forEach((key, deviceInfo) {
List infoList = deviceInfo as List;
BLEDevice device = BLEDevice(
name: infoList[0],
address: infoList[1],
bondState: BondState.getObj(infoList[2]));
bondList.add(device);
});
yield bondList;
Stream<List<BLEDevice>> stream =
_bondListChannel.receiveBroadcastStream().map((list) {
list.forEach((key, deviceInfo) {
List infoList = deviceInfo as List;
BLEDevice device = BLEDevice(
name: infoList[0],
address: infoList[1],
bondState: BondState.getObj(infoList[2]));
bondList.add(device);
});
return bondList;
});
yield* stream;
}