搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目