搜尋套件、儲存庫與 APP 分類

textstyle_extensions 封面
套件詳情v1.1.0

textstyle_extensions

用於輕鬆修改 TextStyle 的語法糖。快速建立 textStyle 變體,例如 .bold、.italic 或 .size()。

近 30 天下載
2360
喜歡數
22
Pub 分數
40

安裝套件

flutter pub add textstyle_extensions

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,為輕鬆修改 TextStyle 提供語法糖。它允許開發者透過直觀的擴展方法(如 .bold、.italic 和 .size())建立樣式化文字變體,簡化自訂文字外觀的過程。透過向 TextStyle 擴展流暢的方法,提升程式碼可讀性並減少重複程式碼。非常適合需要頻繁調整文字樣式的專案,特別是在 UI 豐富的應用中。

適用情境

  • 快速應用粗體或斜體樣式
  • 創建大小調整的文本變體
  • 簡化重複的 TextStyle 修改
  • 增強元件間的UI一致性
  • 提高文字密集型元件中的程式碼可讀性

主要特色

  • TextStyle 的流暢擴展方法
  • 支援 .bold、.italic、.size()
  • 減少文字樣式中的樣板程式碼
  • 提高程式碼可維護性
  • 與現有 TextStyle 物件的輕鬆整合

適合對象

  • 使用富文本的UI開發者
  • 頻繁文字樣式的專案
  • 重視程式碼乾淨、易讀的團隊
  • 具有動態文字格式的 Flutter 應用程式
  • 尋求簡潔文字操作的開發者

使用建議

  • 僅限基本 TextStyle 修改
  • 不支援超出擴展的進階樣式
  • 需要理解 TextStyle 層次結構
  • 可能會稍微增加套件大小
  • 不適用於複雜的文字版面配置情境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

textstyle_extensions

Syntactic sugar for easily modifying TextStyles:

// Do this:
myTextStyle.bold.italic.size(16).letterSpace(1.6)

//Instead of this:
myTextStyle.copyWith(fontSize: 16, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, letterSpacing: 1.6,)

🔨 Installation

dependencies:
  textstyle_extensions: ^1.0.0
⚙ Import
import 'package:textstyle_extensions/textstyle_extensions.dart';

🕹️ Usage

The entire TextStyle API is represented, plus a convenience method for quick scaling:

Widget build(BuildContext context) {
  Text t(String v, TextStyle t) => Text(v, style: t);
  TextStyle style = TextStyle(fontSize: 12);
  return Center(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        t("Normal", style),
        t("Bigger", style.scale(1.1)),
        t("Smaller Bold / Italic / Clr", style.bold.italic.textColor(Colors.redAccent).size(10)),
        t("Weight", style.weight(FontWeight.w100)),
        t("Line Height", style.textHeight(2.5)),
        t("Word Spacing", style.wordSpace(5)),
        t("Letter Spacing", style.letterSpace(3)),
        t("Foreground Paint", style.textForeground(Paint()..color = Colors.orange)),
        t("Background Paint", style.textBackground(Paint()..color = Colors.orange)),
        t("Shadows", style.textShadows([Shadow(color: Colors.redAccent, blurRadius: 4)])),
        t(
          "Decoration",
          style.textDecoration(TextDecoration.underline,
              color: Colors.red, thickness: 4, style: TextDecorationStyle.dotted),
        ),
      ],
    ),
  );
}

Shortcut method names are introduced where it makes sense. This is done both for brevity, and to reduce conflicts with the underlying TextStyle properties.

🐞 Bugs/Requests

If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.

📃 License

MIT License

所屬分類

原始碼儲存庫

使用此套件的專案