搜索插件、代码仓与 APP 分类

插件详情v2.3.0

typeset

WhatsApp 风格的文本样式!-- 加粗、斜体、下划线等 -- 通过后端驱动您的文本样式!

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
5310
喜欢数
108
Pub 分数
150

安装插件

flutter pub add typeset

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Typeset 是一个 Flutter 包,可实现类似 WhatsApp 的富文本样式,支持粗体、斜体、下划线等。它允许开发者通过后端配置动态驱动文本格式化,非常适合消息应用或内容驱动的界面。该包在所有主要平台——Android、iOS、Web、macOS、Windows 和 Linux 上均提供无缝支持,无需复杂的自定义组件即可简化样式文本的实现。通过简单的 pub add 命令即可轻松集成,并提供灵活且可扩展的样式选项。

适合场景

  • 支持富文本的消息应用
  • 从后端动态渲染内容
  • 用户生成的格式化文本
  • 社交媒体风格的文本显示
  • 交互式教育应用

主要特点

  • 后端驱动的文本样式
  • 支持粗体、斜体、下划线
  • 跨平台兼容性
  • 通过 pub 实现轻松集成
  • 最小化样板代码
  • 实时样式更新

适合对象

  • 开发聊天界面的开发者
  • 需要动态文本格式化的应用
  • 通过 API 管理内容的团队
  • 需要在跨平台环境中保持一致的富文本的项目
  • 寻求轻量级样式解决方案的前端开发人员

使用建议

  • 需要正确的后端结构来定义样式
  • 可能需要对用户输入进行额外验证
  • 未针对极大型文本块进行优化
  • 仅限基本文本样式(无高级排版)
  • 依赖于正确的 JSON 解析以应用样式规则

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。


✨ TypeSet ✨

Powerful Text Styling for Flutter

style: very good analysis pub package pub points build status

Transform Your Text Experience

TypeSet brings WhatsApp, Telegram-like text styling to your Flutter apps with a powerful twist. Create rich, dynamic text experiences that can be driven by your backend or controlled directly in your UI.

With TypeSet, you can seamlessly integrate bold, italic, strikethrough, underlined text, monospace, hyperlinks, and even dynamic font sizing without complex widgets or convoluted styling code.

📱 See It In Action

TypeSet Widget TypeSetEditingController
TypeSet Widget TypeSetEditingController

Craft the perfect user experience with text styling that feels natural to your users. TypeSet makes it easy to implement rich text features that would otherwise require complex custom solutions.

🚀 Getting Started

Installation

Add TypeSet to your project by including it in your pubspec.yaml:

dependencies:
  typeset: ^2.3.0  # Check pub.dev for the latest version

Then run:

flutter pub get

💎 Usage

TypeSet is designed to be as simple as using Flutter's built-in Text widget:

import 'package:typeset/typeset.dart';

// Just drop in your formatted text
TypeSet('Hello *Flutter* developers!');
Text Formatting Syntax
Style Syntax Result
Bold *text* text
Italic _text_ text
Strikethrough ~text~ text
Underline #text# text
Monospace `text` text
Link §Link text|https://url§ Link text
Font Size text<size> Renders text at specified size
Advanced Examples
// Hyperlink with custom tap action
TypeSet(
  '§Visit Flutter\|https://flutter.dev§',
  linkRecognizerBuilder: (linkText, url) =>
    TapGestureRecognizer()..onTap = () {
      // Your custom action here
    },
);

// Dynamic font sizing
TypeSet('Regular text with *bigger<24>* words');

// Escape formatting characters
TypeSet('Use the ¦* symbol to show *asterisks*');

💬 Interactive Text Editing

TypeSetEditingController

New in v2.3.0! Add WhatsApp-like styling to your text input fields with real-time formatting preview:

import 'package:typeset/typeset.dart';
import 'package:flutter/material.dart';

// Create a controller with optional styling parameters
final controller = TypeSetEditingController(
  // Initial text with formatting
  text: 'This is *bold* and _italic_',
  // Style for the formatting markers
  markerColor: Colors.grey.shade400,
  // Style for links
  linkStyle: const TextStyle(color: Colors.blue),
  // Style for bold text
  boldStyle: const TextStyle(fontWeight: FontWeight.bold),
  // Style for monospace text
  monospaceStyle: const TextStyle(fontFamily: 'Courier'),
);

// Use it with a TextField
TextField(
  controller: controller,
  maxLines: 3,
  decoration: const InputDecoration(
    border: OutlineInputBorder(),
    hintText: 'Type formatted text here...',
  ),
);
Context Menu Integration

Add formatting options to the text selection context menu with getTypesetContextMenus():

import 'package:typeset/typeset.dart';
import 'package:flutter/material.dart';

TextField(
  controller: TypeSetEditingController(),
  contextMenuBuilder: (context, editableTextState) {
    return AdaptiveTextSelectionToolbar.buttonItems(
      anchors: editableTextState.contextMenuAnchors,
      buttonItems: [
        // Add TypeSet formatting options to the context menu
        ...getTypesetContextMenus(
          editableTextState: editableTextState,
          // Optional: specify which formatting options to include
          // styleTypes: [StyleTypeEnum.bold, StyleTypeEnum.italic],
        ),
        // Keep the default context menu items
        ...editableTextState.contextMenuButtonItems,
      ],
    );
  },
);

This adds formatting buttons (Bold, Italic, Strikethrough, etc.) to the text selection menu, allowing users to easily format selected text.

✨ Key Features

  • WhatsApp-like Formatting - Familiar syntax that users already understand
  • Backend-driven Styling - Update text formatting from your server without app updates
  • TypeSetEditingController - Add rich text capabilities to input fields
  • Dynamic Font Sizing - Adjust text size inline for emphasis or hierarchy
  • Context Menus - Built-in support for copy/paste with formatting
  • Highly Customizable - Style each formatting type independently
  • Lightweight - Minimal dependencies for a smaller app footprint
  • Well-tested - 95%+ test coverage for production reliability

🤝 Community & Support

Contributing

Contributions are welcome! Check out our contribution guidelines to get started.

Support the Project

If TypeSet has been helpful for your projects, consider:

  • ⭐ Starring the repository
  • 🔄 Sharing with other developers
  • 💬 Providing feedback and suggestions
  • 🐛 Reporting bugs and issues

📝 License

TypeSet is available under the Apache License, Version 2.0.


所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目