I'm currently working on BLE support. Because of that, I needed to extend Computer
with the additional field BluetoothDevice? device
. The problem starts when calling download via download
, afterward the object computer no longer contains a valid BluetoothDevice
object. All other fields are fine.
@override
Future<List<Dive>> download(
Computer computer,
ComputerTransport transport, [
String? lastFingerprint,
]) async {
await _send((
DiveComputerMethod.download,
[computer, transport, lastFingerprint],
));
return (_downloadedDives = Completer()).future;
}
class Computer {
Computer(
this.vendor,
this.product, {
this.transports = const [],
});
final String vendor, product;
final List<ComputerTransport> transports;
BluetoothDevice? device;
void addBleDevice(BluetoothDevice device) {
this.device = device;
}
@override
String toString() =>
'$vendor $product ${device ?? ''} [${transports.map((t) => t.name).join(', ')}]';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Computer &&
runtimeType == other.runtimeType &&
vendor == other.vendor &&
product == other.product;
@override
int get hashCode {
// hash codes are not equal across isolates, so we need to generate a
// consistent hash code for each computer
return '$vendor $product'.codeUnits.fold(1, (a, b) => a * b);
}
}