パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリzmeid/pretty-diff-text

pretty-diff-text

PrettyDiffText は、2つのテキスト間の差分を視覚的に表示する RichText のラッパーです。Google の diff-match-patch ライブラリを使用しています。

pretty-diff-text のプロジェクト画像
スター
28
フォーク
11
最終プッシュ(UTC)
2025/04/23
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

PrettyDiffText

Snapshot

PrettyDiffText is wrapper of RichText which demonstrates differences between two texts visually.

By default, it uses Google's diff-match-patch library which implements Myer's diff algorithm. It is generally considered to be the best general-purpose diff.

  • :fire: Pure Dart: It is written purely in Dart.
  • :star: Cross-Platform: Works on Android, iOS, macOS, Windows, Linux and the web.
  • :boom: Highly Customizable: Almost everything can be customized:
    • Text style of AddedText, DeletedText, EqualText.
    • Diff cleanup types: SEMANTIC, EFFICIENCY, NONE.
    • Diff algorithm tuning: DiffTimeout, EditCost.
    • Bring your own diffs: calculate the diffs using your own algorithm.
    • All customization which Flutter's RichText has.

Installing:

Add this to your package's pubspec.yaml file:

dependencies:
  pretty_diff_text: ^2.1.0

Import

import 'package:pretty_diff_text/pretty_diff_text.dart';

How to use

It is easy as using Text widget!

PrettyDiffText(
  oldText: "Your old text",
  newText: "Your new text",
  )

Snapshot

Customization

Those properties are available for customization:

/// The [oldText] is the original text to compare against.
/// The [newText] is the modified text to compare with.
///
/// The [diffCleanupType] determines how the diff results are cleaned up:
/// - [DiffCleanupType.SEMANTIC]: Reduces the number of edits by eliminating semantically trivial equalities (default)
/// - [DiffCleanupType.EFFICIENCY]: Reduces the number of edits by eliminating operationally trivial equalities
/// - [DiffCleanupType.NONE]: No cleanup, raw diff output
///
/// The [defaultTextStyle] is applied to unchanged text.
/// The [addedTextStyle] is applied to text that was added (present in [newText] but not in [oldText]).
/// The [deletedTextStyle] is applied to text that was deleted (present in [oldText] but not in [newText]).
///
/// The [diffTimeout] limits computation time in seconds. If the mapping phase takes longer than this,
/// computation is truncated and returns the best solution found. A value of 0 allows unlimited computation.
///
/// The [diffEditCost] affects cleanup when using [DiffCleanupType.EFFICIENCY]. Higher values result in
/// more aggressive cleanup.
///
/// The following properties are passed directly to the underlying [RichText] widget:
/// - [textAlign]: How the text should be aligned horizontally.
/// - [textDirection]: The directionality of the text.
/// - [softWrap]: Whether the text should break at soft line breaks.
/// - [overflow]: How visual overflow should be handled.
/// - [textScaleFactor]: The number of font pixels for each logical pixel.
/// - [maxLines]: An optional maximum number of lines for the text to span.
/// - [locale]: Used to select region-specific glyphs and formatting.
/// - [strutStyle]: Defines the strut, which sets minimum vertical layout metrics.
/// - [textWidthBasis]: Defines how to measure the width of the rendered text.
/// - [textHeightBehavior]: Defines how the paragraph will apply TextStyle.height to the ascent of the first line and descent of the last line.

Bring Your Own Diffs

If you'd like to calculate your own diffs, you can do so and pass them via the withDiffs contructor:

PrettyDiffText.withDiffs(
  diffs: _getDiffs(
    oldText: _oldTextEditingController.text,
    newText: _newTextEditingController.text,
    diffCleanupType: _diffCleanupType,
    diffTimeout: _diffTimeout,
    diffEditCost: _diffEditCost,
  ),
)

Demo Apps

Clone the demo app to play around: DEMO

Changelog

CHANGELOG

License

MIT License

References:

zmeid GitHub avatar
GitHub 作者

zmeid ↗

言語DartHTMLSwiftKotlinObjective-C

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 2 件

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗