Skip to content

DiffView

A unified-diff viewer: additions, deletions, and hunk/file headers each styled, with an old | new line-number gutter.

See also: PatchReview to review a multi-file patch file by file.

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

DiffView(
diff: '''
@@ -1,3 +1,3 @@
void main() {
- print('hi');
+ print('hello');
}
''',
)

Up and Down move the selected row; PageUp, PageDown, Home, and End jump; clicking a row selects it. Ctrl+C copies the selected row, or its whole hunk, header included, when copyOptions sets DiffViewCopyMode.hunk.

ParameterTypeDefaultDescription
diff:StringrequiredUnified-diff source parsed into document before mounting.
controller:DiffViewController?—External selection and visible-range controller.
focusNode:FocusNode?—Focus node used for keyboard navigation.
autofocus:boolfalseWhether the viewer should request focus when mounted.
semanticLabel:String'Diff'Semantic label (the accessibility name; not rendered) for the diff viewer.
maxLineLength:int?1000Cuts each displayed row (not counting the line-number gutter) to this many characters, ending it with …; null never cuts. Copying still copies the whole row.
showLineNumbers:booltrueWhether to show the old | new line-number gutter. Each row’s line numbers are tracked either way (DiffLine.oldLine, DiffLine.newLine).
copySelection:booltrueWhether Ctrl+C (and the semantic copy action) copies the selected row, or its hunk if copyOptions says so.
copyOptions:DiffViewCopyOptionsconst DiffViewCopyOptions()Clipboard/export options for copied diff text.
onCopy:void Function(DiffViewCopyResult result)?—Called after a copy attempt completes.

Creates a viewer from an already parsed DiffDocument. maxLineLength has no effect here: rows keep the length they were parsed with.

The document’s sanitized, optionally truncated rows are reused without parsing the unified-diff source again.

ParameterTypeDefaultDescription
document:DiffDocumentrequiredParsed unified diff document to render.
controller:DiffViewController?—External selection and visible-range controller.
focusNode:FocusNode?—Focus node used for keyboard navigation.
autofocus:boolfalseWhether the viewer should request focus when mounted.
semanticLabel:String'Diff'Semantic label (the accessibility name; not rendered) for the diff viewer.
maxLineLength:int?1000Cuts each displayed row (not counting the line-number gutter) to this many characters, ending it with …; null never cuts. Copying still copies the whole row.
showLineNumbers:booltrueWhether to show the old | new line-number gutter. Each row’s line numbers are tracked either way (DiffLine.oldLine, DiffLine.newLine).
copySelection:booltrueWhether Ctrl+C (and the semantic copy action) copies the selected row, or its hunk if copyOptions says so.
copyOptions:DiffViewCopyOptionsconst DiffViewCopyOptions()Clipboard/export options for copied diff text.
onCopy:void Function(DiffViewCopyResult result)?—Called after a copy attempt completes.

DiffView is defined in packages/fleury/lib/src/catalog/diff_view.dart.

Category: Agent surfaces · All widgets