Open
Description
The issue now is that platform-specific arguments are only marked so in Dart docs.
peripheral.dart
/// Connects to the peripheral.
///
/// Optional [isAutoConnect] controls whether to directly connect to the
/// remote peripheral (`false`) or to automatically connect as soon as the
/// remote peripheral becomes available (true). (Android only)
///
/// Optional [requestMtu] size will be negotiated to this value. It is not
/// guaranteed to get it after connection is successful. (Android only)
/// iOS by default requests about 186 MTU size and there's nothing anyone can
/// do about it.
/// **NOTE**: if MTU has been request on this step, then there's no way
/// to retrieve it's value later on.
///
/// Optional [requestMtu] means that the MTU will not be negotiated
/// Passing `true` as [refreshGatt] leads reset services cache. This option may
/// be useful when a peripheral's firmware was updated and it's
/// services/characteristics were added/removed/altered. (Android only)
///
/// Optional [timeout] is used to define time after connection is
/// automatically timed out. In case of race condition were connection
/// is established right after timeout event, peripheral will be disconnected
/// immediately. Timeout may happen earlier then specified due to OS
/// specific behavior.
Future<void> connect(
{bool isAutoConnect = false,
int requestMtu = NO_MTU_NEGOTIATION,
bool refreshGatt = false,
Duration timeout})
The solution is to change method signature to accept objects:
class Peripheral {
..
Future<void> connect(
{Duration timeout,
AndroidConnectionArguments androidOptions,
iOSConnectionArguments iosOptions,
})
..
}
class iOSConnectionArguments {
bool isNotifyOnConnection;
bool isNotifyOnDisconnection;
bool isNotifyOnNotification;
const constructor(bool isNotifyConnection = false...
}
class AndroidConnectionArguments {
bool isAutoConnect;
int requestMtu;
bool refreshGatt;
}
To avoid a breaking change existing parameters have to be marked as deprecated and docs must explain that the new objects take priority if both ways are used.