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

pretty_diff_text のカバー
パッケージ詳細v2.1.0

pretty_diff_text

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

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.7万
いいね数
66
Pub ポイント
160

パッケージをインストール

flutter pub add pretty_diff_text

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

PrettyDiffTextは、2つのテキスト文字列間の違いを視覚的に強調するためのRichTextをラップするFlutterパッケージです。正確かつ効率的なテキスト比較のためにGoogleのdiff-match-patchライブラリを利用しており、編集や変更、修正を読みやすく表示するのに最適です。このパッケージは複数のプラットフォームをサポートし、リアルタイムまたは歴史的なテキスト比較が必要なアプリにスムーズに統合できます。追加、削除、変更を色とフォーマットで明確にマークすることで、ユーザー体験を向上させます。

用途

  • 共同作業アプリでのテキストの修正を表示
  • コードまたはドキュメントの変更を可視化する
  • メモアプリでの編集履歴の表示
  • バージョン付きコンテンツの違いを強調する
  • チャットまたはメッセージ内のリアルタイムテキスト比較
  • 設定や設定の更新を追跡する

主な機能

  • 正確な比較に diff-match-patch を使用します
  • 豊富なテキスト形式をサポート
  • 色分けされた追加および削除
  • クロスプラットフォーム互換性
  • 既存の RichText ウィジェットとの簡単な統合
  • カスタマイズ可能なスタイルオプション

適している対象

  • 編集または共同作業ツールを開発する開発者
  • 変更追跡が必要なアプリ
  • 教育またはドキュメンテーションプラットフォーム
  • バージョン管理インターフェース
  • 動的テキスト更新を表示する UI

注意事項

  • 単純なケースにおいて、ウィジェットの複雑さを増加させる可能性があります
  • 非常に長いテキストによるパフォーマンスへの影響
  • ネストされたリッチテキストの取り扱いに注意が必要です
  • 基本的なスタイル設定を超えるカスタマイズが限られている
  • 外部の diff-match-patch ライブラリに依存しています
  • 高頻度の更新には最適化されていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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:

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト