패키지, 저장소 및 앱 카테고리 검색

pretty_diff_text 표지
패키지 상세v2.1.0

pretty_diff_text

PrettyDiffText는 두 텍스트 간의 차이점을 시각적으로 표시하는 RichText의 래퍼입니다. 기본적으로 Google의 diff-match-patch 라이브러리를 사용합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.7만
좋아요
66
Pub 점수
160

패키지 설치

flutter pub add pretty_diff_text

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

PrettyDiffText는 두 텍스트 문자열 간의 차이를 시각적으로 강조하기 위해 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 개

소스 저장소

이 패키지를 사용하는 프로젝트