Announcement.parse constructor

Announcement.parse(
  1. String text
)

Constructs an Announcement from the provided text.

First line of the text, if there's multiple present, is considered as a title.

Implementation

factory Announcement.parse(String text) {
  final split = text.split('\n');
  if (split.length >= 2) {
    final String title = split.first;
    return Announcement(
      title: title.trim(),
      body: text.substring(title.length + 1).trim(),
    );
  }

  return Announcement(title: text);
}