Buscar pacotes, repositórios e categorias de apps

Capa de pretty_diff_text
Detalhes do pacotev2.1.0

pretty_diff_text

PrettyDiffText é um invólucro do RichText que mostra visualmente as diferenças entre dois textos. Usa a biblioteca diff-match-patch do Google por padrão.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
16,5 mil
Curtidas
66
Pontos Pub
160

Instalar pacote

flutter pub add pretty_diff_text

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

PrettyDiffText é um pacote Flutter que envolve o RichText para destacar visualmente as diferenças entre duas strings de texto. Ele utiliza a biblioteca diff-match-patch do Google para comparação de texto precisa e eficiente, tornando-o ideal para mostrar edições, alterações ou revisões em um formato legível. O pacote suporta múltiplas plataformas e se integra perfeitamente em aplicativos que precisam de comparação de texto em tempo real ou histórica. Ele melhora a experiência do usuário ao marcar claramente adições, exclusões e modificações com cor e formatação.

Casos de uso

  • Mostrando revisões de texto em aplicativos colaborativos
  • Visualizando alterações no código ou documento
  • Exibindo o histórico de edição em aplicativos de anotações
  • Destacando diferenças no conteúdo versão
  • Comparação de texto em tempo real em bate-papo ou mensagens
  • Atualizações de rastreamento em configuração ou configurações

Principais recursos

  • Usa diff-match-patch para comparações precisas
  • Suporta formatação de texto rico
  • Adições e exclusões com codificação de cor
  • Compatibilidade multiplataforma
  • Integração fácil com widgets RichText existentes
  • Opções de estilização personalizáveis

Indicado para

  • Desenvolvedores construindo ferramentas de edição ou colaboração
  • Aplicativos que exigem rastreamento de alterações
  • Plataformas educacionais ou de documentação
  • Interfaces de controle de versão
  • Interfaces de usuário exibindo atualizações de texto dinâmico

Considerações

  • Pode aumentar a complexidade do widget em casos simples
  • Impacto no desempenho com textos muito longos
  • Requer manipulação cuidadosa de texto rico aninhado
  • Personalização limitada além do estilo básico
  • Depende da biblioteca externa diff-match-patch
  • Não otimizado para atualizações de alta frequência

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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:

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote