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

패키지 상세v2.0.49

simple_rich_text

간단한 리치 텍스트 문자를 사용하여 Flutter에서 Dart 문자열을 표시합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
7.7천
좋아요
88
Pub 점수
150

패키지 설치

flutter pub add simple_rich_text

패키지 개요

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

Dart 문자열에서 간단한 리치 텍스트 렌더링을 가능하게 하는 플러터 패키지로, 직관적인 구문을 사용하여 텍스트에 기본 스타일을 적용할 수 있습니다. 볼드, 이탤릭, 색상과 같은 일반적인 포맷팅은 임베디드 문자를 통해 지원되며, 복잡한 위젯 계층 없이 스타일이 적용된 텍스트를 쉽게 표시할 수 있습니다. 최소한의 보일러플레이트로 가볍고 읽기 쉬운 텍스트 포맷팅이 필요한 앱에 적합합니다. 이 패키지는 크로스플랫폼이며 Android, iOS, 웹, macOS, Windows, Linux에서 원활하게 작동합니다.

사용 사례

  • 형식이 지정된 사용자 메시지 표시
  • 스타일화된 알림 렌더링
  • 동적 텍스트 레이블 만들기
  • 채팅 인터페이스에서 풍부한 콘텐츠 표시
  • 최소 코드로 UI 향상

주요 기능

  • 간단한 문자 기반 형식 지정
  • 크로스 플랫폼 지원
  • 최소한의 위젯 중첩
  • 강조, 기울임꼴 및 색상 지원
  • 기존 텍스트 위젯과의 간편한 통합

적합한 대상

  • 초보자 플러터 개발자
  • 간단한 텍스트 스타일링 필요가 있는 앱
  • 채팅 또는 메시지 인터페이스
  • 경량 리치 텍스트 요구 사항
  • 빠른 프로토타이핑

고려 사항

  • 기본 형식 지정에 제한됨
  • 복잡한 레이아웃에 적합하지 않습니다
  • 고급 타이포그래피 지원 없음
  • 조심스럽게 문자열 이스케이프가 필요합니다
  • 과도하게 사용할 경우 가독성에 영향을 줄 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

simple_rich_text

Easily format Flutter text with simple format characters.

Motivation: lowest-possible development friction to add color and formatting to text.

In comparison, easy_rich_text requires lots of code (i.e, patternList of EasyRichTextPattern objects).

Format Characters

These are non-standard (not markdown compatible) but are more intuitive, in my opinion:

format character format effect simple_rich_text string input Flutter output
asterisk (*) bold "this is *bold*" this is bold
slash (/) italics "this is /italicized/" this is italicized
underscore (_) underline "this is _underlined_" this is underlined

Example Input

SimpleRichText(r'*_/this is all three*_/ (*{color:red}bold*, _{color:green}underlined_, and /{color:brown}italicized/). _{push:home;color:blue}clickable hyperlink to home screen_')

Example Flutter Output

Screenshot

Attributes

Attribute pairs are placed in curly brackets immediately after first character marker. Each pair is separated by a semicolon (;) and can be in any order. Each pair has syntax name:value.

key meaning implemented Dart code
color red, blue, etc textStyle.color: color-value
pop pop the navigation stack Navigator.pop(context);
push push the value onto the navigation stack Navigator.pushNamed(context, '/$route');
repl replace the top route on the navigation stack Navigator.popAndPushNamed(context, '/$route');

Colors Supported

Change text color by passing color as attribute:

Example

"this is blue hyperlink to the _{color:blue,push:calendar}calendar_ screen"
color:color_value hex value
aqua 0x00FFFF
black 0x000000
blue 0x0000FF
brown 0x9A6324
cream 0xFFFDD0
cyan 0x46f0f0
green 0x00FF00
gray 0x808080
grey 0x808080
mint 0xAAFFC3
lavender 0xE6BEFF
new 0xFFFF00
olive 0x808000
orange 0xFFA500
pink 0xFFE1E6
purple 0x800080
red 0xFF0000
silver 0xC0C0C0
white 0xFFFFFF
yellow 0xFFFF00

Features

  • support text hyperlinks to other screens by preceding formatted text with route inside curly brackets: e.g., "... {calendar}go to calendar screen".

Sample Inputs:

'this is /italic/'

'this is *bold*'

'*_/this is all three*_/ (*bold*, _underlined_, and /italicized/)'

'you can quote characters to NOT format a word \*bold\*'

'this is _underline_'

'go to _{/myroute}home_ page'

'this is ~important~(red).'

'this is _*bold and underlined*_.'

Notes

You can use multiple characters at the same time:

"this is _/underlined and italicized/_"

You can be sloppy! Unlike HTML, for convenience, if using multiple characters the open and closed sequences, they don't need to be in exact palindrome matching order:

"these are */equivalent/* and works without problems."
"these are */equivalent*/ and works without problems."

Requirements

Ancestor MUST have textDirection set (required by internal RichText widget), either through MaterialApp widget or explicitly wrapped by a Directionality widget:

Directionality(
    child: SimpleRichText('Peter', term: 't'),
    textDirection: TextDirection.ltr)

Improvements, Bugs, and Deficiencies

  • [ ] user-definable format characters
  • [ ] user-definable callback functions for custom formatting
  • [ ] support non-named navigation (only pushNamed, etc., supported at present)

Pull Requests

Pull requests are welcome!

Examples

See the example directory.

카테고리

의존성

의존성 목록 1 개

소스 저장소

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

아직 데이터가 없습니다.