toJson method

Map<String, dynamic> toJson({
  1. @Deprecated('Will not have replacement') String textSeparator = '',
})

Convert this to a json representation valid for the Notion API.

Deprecated: textSeparator will be removed and the separation will be by your own. This because that's the same way that Text & RichText works on Flutter. In this way you can add annotations for a part of a word instead of only full words or phrases.

If a textSeparator is given, then it's value (by default a space) is append at the end of the string to allow be at the same level of other Text objects without being all together. For example:

// using default (space)
blocks.append(
  to: 'some_block_id',
  children: Children(
    paragraph: Paragraph([
      Text('A'),
      Text('B',)
    ])));
// append => "A B "

// using custom
blocks.append(
  to: 'some_block_id',
  children: Children(
    paragraph: Paragraph([
      Text('A'),
      Text('B',)
    ],
    textSeparator: '-')));
// append => "A-B-"

Implementation

Map<String, dynamic> toJson(
    {@Deprecated('Will not have replacement') String textSeparator: ''}) {
  Map<String, dynamic> json = {
    'type': _type,
    'text': {
      'content': '$text$textSeparator',
    },
  };

  // Null values on fields can break the API call.
  if (annotations != null) {
    json['annotations'] = annotations?.toJson();
  }

  if (url != null) {
    json['link'] = {
      'url': url.toString(),
    };
  }

  return json;
}