flutter_diff_viewer library
A production-grade Flutter package providing GitHub/GitLab-style content comparison and diff viewing.
Quick Start
import 'package:flutter_diff_viewer/flutter_diff_viewer.dart';
FlutterDiffViewer(
oldContent: 'Hello World',
newContent: 'Hello Dart',
)
Advanced Usage
FlutterDiffViewer(
oldContent: oldText,
newContent: newText,
configuration: FlutterDiffViewerConfiguration(
layout: DiffLayout.sideBySide,
granularity: DiffGranularity.word,
collapseUnchangedLines: true,
theme: FlutterDiffViewerTheme.dark(),
typography: DiffTypography.defaults(),
spacing: DiffSpacing.defaults(),
localizations: DiffLocalizations.defaults(),
),
controller: myController,
diffEngine: myCustomEngine,
)
Classes
- CalculateDiff
- Use case for calculating the diff between two text contents.
- DiffChange
- An immutable entity representing a navigable change within a diff result.
- DiffComparisonOptions
- Immutable value object encapsulating all options that control how a diff comparison is performed.
- DiffEngine
- Abstract interface for diff engine implementations.
- DiffLine
- An immutable entity representing a single line (or pair of lines) in a diff.
- DiffLineNumber
- Immutable value object representing a 1-based line number in a diff view.
- DiffLocalizations
- An immutable set of user-visible strings for the diff viewer.
- DiffRepository
- Abstract interface for the diff comparison repository.
- DiffResult
- An immutable entity representing the complete result of a diff comparison.
- DiffSegment
- An immutable entity representing a contiguous run of text with a single DiffType classification.
- DiffSpacing
- An immutable set of spacing and sizing constants for the diff viewer.
- DiffTypography
- An immutable set of TextStyles used throughout the diff viewer.
- FlutterDiffViewer
- The primary widget for displaying content comparison diffs.
- FlutterDiffViewerConfiguration
- The top-level configuration object for the diff viewer widget.
- FlutterDiffViewerController
- Controls a FlutterDiffViewer widget's navigation, scrolling, and collapse state.
- FlutterDiffViewerTheme
- An immutable theme that controls every color used by the diff viewer.
- SideBySideDiffView
- Renders a side-by-side diff view with synchronized scrolling.
- StackedDiffView
- Renders a stacked diff view (old content above, new content below).
- UnifiedDiffView
- Renders a unified diff view (single column, +/- indicators).
Enums
- DiffGranularity
- Controls the granularity of diff comparison within lines.
- DiffLayout
- Controls the visual layout of the diff viewer.
- DiffType
- Represents the type of a diff change between two content versions.
- FlutterDiffViewerState
- State of the diff viewer.
Typedefs
- Builder for the change-navigation bar (previous / next buttons).
- DiffCollapsedSectionBuilder = Widget Function(BuildContext context, int collapsedLineCount, VoidCallback onExpand, FlutterDiffViewerConfiguration configuration)
- Builder for collapsed-section placeholder rows.
- DiffEmptyStateBuilder = Widget Function(BuildContext context, FlutterDiffViewerConfiguration configuration)
- Builder for the empty state shown when no changes are detected.
- DiffErrorBuilder = Widget Function(BuildContext context, Object error, FlutterDiffViewerConfiguration configuration)
- Builder for the error state shown when diff computation fails.
- Builder for the footer section rendered below the diff content.
- DiffHeaderBuilder = Widget Function(BuildContext context, String? oldLabel, String? newLabel, FlutterDiffViewerConfiguration configuration)
- Builder for the header bar of the diff viewer.
- DiffIndicatorBuilder = Widget Function(BuildContext context, DiffLine line, FlutterDiffViewerConfiguration configuration)
- Builder for the change-indicator column cell within a diff row.
- DiffLineBuilder = Widget Function(BuildContext context, DiffLine line, FlutterDiffViewerConfiguration configuration)
- Builder for an individual diff line row.
- DiffLineNumberBuilder = Widget Function(BuildContext context, int? lineNumber, FlutterDiffViewerConfiguration configuration)
- Builder for the line-number gutter cell within a diff row.
- DiffLoadingBuilder = Widget Function(BuildContext context, FlutterDiffViewerConfiguration configuration)
- Builder for the loading state while the diff is being computed.
- DiffSegmentBuilder = Widget Function(BuildContext context, DiffSegment segment, FlutterDiffViewerConfiguration configuration)
- Builder for a single intra-line diff DiffSegment.
- DiffSummaryBuilder = Widget Function(BuildContext context, DiffResult result, FlutterDiffViewerConfiguration configuration)
- Builder for the summary statistics bar.
Exceptions / Errors
- DiffCalculationException
- Thrown when the diff engine encounters an internal failure during calculation.
- DiffConfigurationException
- Thrown when the diff viewer is configured with invalid or incompatible settings.
- DiffException
- Base class for all exceptions thrown by the flutter_diff_viewer package.
- DiffIndexOutOfBoundsException
- Thrown when a requested change index is out of bounds.
- InvalidDiffInputException
- Thrown when the inputs provided for diff calculation are invalid.