As it says in the flutter_blue documentation, manufactureData is returned as a Map object and you appear to be asking how to get the value for the Map key/value pair.
This is covered in the following tutorial:
https://www.tutorialspoint.com/dart_programming/dart_programming_map.htm
The general case is map_name[key]
. In your example the key is 256
and the map_name is KCBAdvDataManufacturerData
so to get the list, it would be KCBAdvDataManufacturerData[256]
This looks linked to your previous question, so to put that in a more complete example:
import 'dart:typed_data';
var bleData = {256:[0,0,0,16,1,57,33,18,0,0,154,10,0,0,94,0]};
main() {
parseManufacturerData(bleData);
}
parseManufacturerData(data) {
var manufacturerData = Uint8List.fromList(data[256]);
var pressure = ByteData.sublistView(manufacturerData, 6, 10);
var temperature = ByteData.sublistView(manufacturerData, 10, 14);
var battery = ByteData.sublistView(manufacturerData, 14, 15);
print("Pressure: ${pressure.getUint32(0, Endian.little)/100} psi");
print("Temperature: ${temperature.getUint32(0, Endian.little)/100} \u{00B0}C");
print("Battery: ${battery.getUint8(0)} %");
}
When I run this at https://dart.dev/#try-dart it gives:
Pressure: 46.41 psi
Temperature: 27.14 °C
Battery: 94 %
I have no way of testing the following code, but this how I would try modifying the Scan for devices example at https://pub.dev/documentation/flutter_blue/latest/index.html:
// Start scanning
flutterBlue.startScan(timeout: Duration(seconds: 4));
// Listen to scan results
var subscription = flutterBlue.scanResults.listen((results) {
// do something with scan results
for (ScanResult r in results) {
print('${r.advertisementData.manufacturerData}');
// Pass it to our previous function
parseManufacturerData(r.advertisementData.manufacturerData)
}
});
// Stop scanning
flutterBlue.stopScan();
I am expecting the key value in the advertisementData.manufacturerData
to be the Company ID. The thing that is confusing me, is the value of decimal 256 in your example is for TomTom International BV which might not be the device sending the pressure, temperature, and battery values. If that is the case, then you will need some logic in the code to only call parseManufacturerData
if it is the device of interest.