publishMessage method Null safety

int publishMessage(
  1. String topic,
  2. MqttQos qualityOfService,
  3. Uint8Buffer data,
  4. {bool retain = false}

Publishes a message to the message broker. Returns The message identifer assigned to the message. Raises InvalidTopicException if the topic supplied violates the MQTT topic format rules.


int publishMessage(
    String topic, MqttQos qualityOfService, typed.Uint8Buffer data,
    {bool retain = false}) {
  if (connectionHandler?.connectionStatus?.state !=
      MqttConnectionState.connected) {
    throw ConnectionException(connectionHandler?.connectionStatus?.state);
  try {
    final pubTopic = PublicationTopic(topic);
    return publishingManager!
        .publish(pubTopic, qualityOfService, data, retain);
  } on Exception catch (e) {
    throw InvalidTopicException(e.toString(), topic);