createTopic method

  1. @override
Future<void> createTopic({
  1. required String topicName,
  2. List<TopicMetaData> metaData = const [],
  3. dynamic callback(
    1. FlyResponse response
    )?,
})
override

This method is used to create the topic.

Implementation

@override
Future<void> createTopic(
    {required String topicName,
    List<TopicMetaData> metaData = const [],
    Function(FlyResponse response)? callback}) async {
  String? topicId = FlyConstants.empty;
  List<Map<String, dynamic>>? topic =
      metaData.map((topic) => topic.toMap()).toList();
  LogMessage.d("createTopic", topic);
  //if (metaData.length <= 3) {
  try {
    topicId = await mirrorFlyMethodChannel.invokeMethod(
        'createTopic', {'topicName': topicName, 'metaData': topic});
    LogMessage.d('createTopic', ' $topicId');
    callback?.call(FlyResponse(
        true, topicId ?? FlyConstants.empty, "Topic created successfully"));
    // return topicId;
  } on PlatformException catch (e) {
    LogMessage.d("Platform Exception =", " $e");
    callback?.call(FlyResponse(false, FlyConstants.empty, FlyConstants.empty,
        FlyException(e.code, e.message, e.details)));
    // rethrow;
  } on Exception catch (e) {
    LogMessage.d("Exception ", " $e");
    callback?.call(FlyResponse(false, FlyConstants.empty, FlyConstants.empty,
        FlyException(FlyErrorCode.unHandle, FlyErrorMessage.unHandle, e)));
    // rethrow;
  }
  // } else {
  //   throw Exception("topicData Maximum Size is 3");
  // }
}