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

rounded_background_text 표지
패키지 상세v0.6.0

rounded_background_text

둥근 모서리로 강조된 Text, TextField 및 TextSpan

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.7천
좋아요
101
Pub 점수
150

패키지 설치

flutter pub add rounded_background_text

패키지 개요

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

Text, TextField, TextSpan을 포함한 텍스트 요소에 둥근 모서리 배경을 추가하는 플러터 패키지입니다. 사용자 정의 가능한 색상, 테두리 반경 및 패딩을 통해 시각적으로 매력적인 텍스트 강조를 가능하게 합니다. 텍스트 가독성과 디자인 감각을 중시하는 현대적인 UI 제작에 이상적입니다. 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 모든 주요 플랫폼을 지원하여 기기 간 일관된 스타일링을 보장합니다. 단일 pub add 명령어로 간편하게 통합되어, 복잡한 커스텀 페인팅 없이도 우아한 텍스트 효과를 쉽게 구현할 수 있습니다.

사용 사례

  • 앱에서 핵심 텍스트 강조하기
  • 스타일링된 입력 필드 만들기
  • 레이블에 시각적 강조 추가
  • 현대적인 UI 컴포넌트 설계
  • 대비를 통한 접근성 향상
  • 상호작용형 텍스트 요소 만들기

주요 기능

  • 텍스트용 둥근 모서리 배경
  • 둥근 배경을 가진 TextField 지원
  • 사용자 정의 가능한 테두리 반지름 및 패딩
  • TextSpan과 호환됩니다
  • 크로스 플랫폼 지원
  • pub.dev를 통한 간편한 통합

적합한 대상

  • 시각적 완성도를 추구하는 UI 디자이너
  • 현대적인 Flutter 앱을 개발하는 개발자
  • 강조된 텍스트 요소가 필요한 앱
  • 접근성과 가독성에 중점을 둔 프로젝트
  • 빠른 효과 구현을 원하는 팀

고려 사항

  • 많은 인스턴스가 있는 경우 성능에 영향을 미칠 수 있습니다
  • 접근성 위해 색 대비를 신중하게 고려해야 합니다
  • 텍스트 장식 사용 사례에 한정
  • 복잡한 레이아웃에 적합하지 않습니다
  • 플랫폼 렌더링 일관성에 의존
  • 시각적 혼잡을 피하기 위해 적절히 사용하는 것이 좋습니다

원본 README

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

rounded_background_text

Highlight text with rounded corners

Content

Features

  • ✅ Highlight Text
  • ✅ Highlight Text Field
  • ✅ Highlight Text Span

Getting started

Import the package:

import 'package:rounded_background_text/rounded_background_text.dart';

Usage

Highlight a simple text:
RoundedBackgroundText(
  'A cool text to be highlighted',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.white,
),

Simple Text

Multiline text is also supported

RoundedBackgroundText(
  'A cool text to be highlighted\nWith two lines or more',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.amber,
),

Two Lines Text

Highlight a text field:

You must use a TextEditingController

RoundedBackgroundTextField(
  backgroundColor: Colors.blue,
  style: const TextStyle(fontWeight: FontWeight.bold),
  textAlign: TextAlign.center,
),

The text will be highlighted as the user types

TextField Preview

The text highlight will follow the text field scroll position.

Highlight a text span:

Highlight a small part of a text

RichText(
  text: TextSpan(
    text: 'Start your text and ',
    children: [
      RoundedBackgroundTextSpan(
        text: 'highlight something',
        backgroundColor: Colors.blue,
      ),
      const TextSpan(text: ' when necessary'),
    ],
  ),
),

TextSpan Highlight Preview

Select a highlighted text:

Use RoundedBackgroundText.selectable to make the text selectable:

RoundedBackgroundText.selectable(
  'A cool highlighted text to be selected',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.white,
),

Selectable Text Preview

You may like to know:

Change the corner radius

You can change the radius of the corners by setting innerRadius and outerRadius:

RoundedBackgroundText(
  'A cool text to be highlighted',
  style: const TextStyle(fontWeight: FontWeight.bold),
  backgroundColor: Colors.white,
  innerRadius: 15.0,
  outerRadius: 10.0,
),

The max allowed value is 20.0. The min is 0.0

Deep dive

This section explains, with details, how the background painting works.

RoundedBackgroundText doesn't use a Text widget under the hood. Instead, it uses a custom text painter to paint the text above the background. As soon as the RoundedBackgroundText widget is initialized, the line metrics for the text is calculated (See computeLineMetrics), and is recalculated when the text changes or when the parent width changes. This is done at built time, resulting in a smooth experience for the user.

To paint the background, the line metrics generated before is used. Each line has 4 properties:

  • x - where the line starts horizontally within the size
  • y - where the line starts vertically within the size
  • width - the horizontal size of the line
  • height - the vertical size of the line

With these values, we can generate the background for each line. The background is generated around the whole text: from top-left to bottom-left to bottom-right to top-right to top-left. This makes it easy to calculate when there is a corner, either outer or inner.

The inner and outer radius are dynamically calculated based on the line height, provided by the line metrics, and the given innerRadius and outerRadius, respectively. By default, innerRadius is 10.0 and outerRadius is 10.0. For safety, in order to keep the roundnesses correct, these values must be in the bounds of 0.0 (min) and 20.0 max, otherwise the painting would be out the line.

Contribution

Feel free to file an issue if you find a problem or make pull requests.

All contributions are welcome!

카테고리

소스 저장소

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