updateParagraph method
Update a paragraph
into the document validating to make more safe the operation.
Implementation
void updateParagraph(Paragraph paragraph) {
int lastIndex = paragraphs.lastIndexOf(paragraph);
// make a second check to be sure that it does exist or not
if (lastIndex == -1 && paragraphs.isNotEmpty) {
lastIndex = paragraphs.indexWhere((pr) => pr.id == paragraph.id);
}
if (paragraphs.isEmpty || lastIndex == -1) {
throw StateError(
'Not found element of type ${paragraph.runtimeType} with id: ${paragraph.id}');
}
paragraphs[lastIndex] = paragraph;
}