pretty_diff_text 1.0.0 copy "pretty_diff_text: ^1.0.0" to clipboard
pretty_diff_text: ^1.0.0 copied to clipboard

PrettyDiffText is wrapper of RichText which shows differences between two texts visually. It uses Google's diff-match-patch library.

PrettyDiffText #

Snapshot

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

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.

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

Installing: #

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

dependencies:
  pretty_diff_text: ^1.0.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:

  /// Default text style of RichText. Mainly will be used for the text which did not change.
  /// [addedTextStyle] and [deletedTextStyle] will inherit styles from it.
  final TextStyle defaultTextStyle;

  /// Text style of text which was added.
  final TextStyle addedTextStyle;

  /// Text style of text which was deleted.
  final TextStyle deletedTextStyle;

  /// See [DiffCleanupType] for types.
  final DiffCleanupType diffCleanupType;

  /// If the mapping phase of the diff computation takes longer than this,
  /// then the computation is truncated and the best solution to date is
  /// returned. While guaranteed to be correct, it may not be optimal.
  /// A timeout of '0' allows for unlimited computation.
  /// The default value is 1.0.
  final double diffTimeout;

  /// Cost of an empty edit operation in terms of edit characters.
  /// This value is used when [DiffCleanupType] is selected as [DiffCleanupType.EFFICIENCY]
  /// The larger the edit cost, the more aggressive the cleanup.
  /// The default value is 4.
  final int diffEditCost;

  /// !!! DERIVED PROPERTIES FROM FLUTTER'S [RichText] IN ORDER TO ALLOW CUSTOMIZABILITY !!!
  /// See [RichText] for documentation.
  ///
  final TextAlign textAlign;
  final TextDirection? textDirection;
  final bool softWrap;
  final TextOverflow overflow;
  final double textScaleFactor;
  final int? maxLines;
  final Locale? locale;
  final StrutStyle? strutStyle;
  final TextWidthBasis textWidthBasis;
  final TextHeightBehavior? textHeightBehavior;
enum DiffCleanupType {
  /// Increase human readability by factoring out commonalities which are likely to be coincidental.
  SEMANTIC,

  /// Increase computational efficiency by factoring out short commonalities which are not worth the overhead.
  /// The larger the edit cost(see: [PrettyDiffText::diffEditCost]), the more aggressive the cleanup.
  EFFICIENCY,

  /// No cleanup. Raw output.
  NONE
}

Demo App #

Clone the demo app to play around: DEMO

Changelog #

CHANGELOG

License #

MIT License

References: #

44
likes
130
pub points
83%
popularity

Publisher

unverified uploader

PrettyDiffText is wrapper of RichText which shows differences between two texts visually. It uses Google's diff-match-patch library.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

diff_match_patch, flutter

More

Packages that depend on pretty_diff_text