getSelectedContent method Null safety

  1. @override
SelectedContent? getSelectedContent()
override

Copies the selected contents of all selectables.

Implementation

@override
SelectedContent? getSelectedContent() {
  final List<SelectedContent> selections = <SelectedContent>[];
  for (final Selectable selectable in selectables) {
    final SelectedContent? data = selectable.getSelectedContent();
    if (data != null) {
      selections.add(data);
    }
  }
  if (selections.isEmpty) {
    return null;
  }
  final StringBuffer buffer = StringBuffer();
  for (final SelectedContent selection in selections) {
    buffer.write(selection.plainText);
  }
  return SelectedContent(
    plainText: buffer.toString(),
  );
}