toJson method Null safety

  1. @override
Map<String, dynamic> toJson()
override

Implementation

@override
Map<String, dynamic> toJson() {
  final ret = super.toJson();

  if (ret['mentioned_user_ids'] == null) {
    List? result = ret['mentioned_users'];

    var userList = result?.map((e) => e['user_id'].toString()).toList();

    if (userList?.isNotEmpty ?? false) {
      ret['mentioned_user_ids'] = userList;
    }
  }

  ret['poll_id'] = pollId;
  ret['message'] = message;
  ret['target_langs'] = targetLanguages;
  if (targetLanguages.isNotEmpty) {
    ret['translations'] = {for (var e in targetLanguages) e: ''};
  }
  ret['extended_message'] = extendedMessage;
  ret.removeWhere((key, value) => value == null);
  return ret;
}