Review and comments
You will add tracked changes (suggesting mode), comments with replies, and accept/reject from code.
Packages
None: review is part of the core and the editor.
The code
dart
import 'package:flutter/material.dart';
import 'package:vyuh_document_editor/vyuh_document_editor.dart';
/// Comments and suggested changes on the same controller.
Widget buildReviewEditor(
DocumentEditorController controller,
DocumentInteractionMode mode,
) => DocumentEditor(
controller: controller,
// editing, suggesting (tracked changes), commenting, reviewing or viewing.
interactionMode: mode,
configuration: DocumentEditorConfiguration(
review: DocumentReviewConfiguration(
showComments: true,
showRevisions: true,
// Collect comment text in your own UI; return null to cancel.
commentComposer: (controller, selection) async => 'Please cite this.',
),
),
);
void reviewFromCode(DocumentEditorController controller) {
// Comment the current selection, then reply to it.
final commentId = controller.addCommentToSelection('Is this final?');
if (commentId != null) {
controller.addReplyToComment(commentId, 'Yes, approved.');
controller.setCommentResolved(commentId, true);
}
// Accept or reject every recorded suggestion.
for (final revision in controller.document.revisions) {
controller.acceptRevision(revision.id);
}
}Switch mode to DocumentInteractionMode.suggesting and type: insertions get a green dashed underline, deletions a red strikethrough. In commenting mode, selecting a word asks your commentComposer for the text.
Interaction modes
DocumentInteractionMode | Users can |
|---|---|
editing | Edit directly |
suggesting | Edit; every change is recorded as a suggestion |
commenting | Select and comment, not edit |
reviewing | Review suggestions and comments |
viewing | Read and select |
Set it on the widget (DocumentEditor(interactionMode:)) or the controller (configureInteractionMode).
Review API on the controller
| Method | Does |
|---|---|
addCommentToSelection(text) | Adds a comment; returns its ID |
addReplyToComment(id, text), updateComment, deleteComment | Thread management |
setCommentResolved(id, resolved) | Resolve or reopen |
acceptRevision(id), rejectRevision(id) | Decide a suggestion |
protectSelection(), unprotectSelection() | Protected regions (template design) |
How each kind of suggestion looks is described in Transactions and history.