パッケージ、リポジトリ、アプリカテゴリを検索

rounded_background_text のカバー
パッケージ詳細v0.6.0

rounded_background_text

丸みのあるコーナーで強調された Text、TextField および TextSpan

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
2690
いいね数
101
Pub ポイント
150

パッケージをインストール

flutter pub add rounded_background_text

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Text、TextField、TextSpan を含むテキスト要素に丸みのあるコーナーの背景を追加する Flutter パッケージです。カスタマイズ可能な色、ボーダー半径、パディングで視覚的に魅力的なテキストハイライトが可能になります。テキストの読みやすさとデザインの洗練を重視したモダンな UI の作成に最適です。Android、iOS、Web、macOS、Windows、Linux といったすべての主要プラットフォームをサポートしており、デバイス間でのスタイルの一貫性を確保します。単一の 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!

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト