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

插件详情v3.0.1

rich_text_controller

一个扩展的文本编辑控制器,支持为自定义正则表达式模式设置不同的内联样式。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7920
喜欢数
104
Pub 分数
160

安装插件

flutter pub add rich_text_controller

插件介绍

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

rich_text_controller 是一个 Flutter/Dart 包,扩展了标准文本编辑控制器,以基于自定义正则表达式实现文本的内联样式。它允许开发者为文本字段中的特定模式(如话题标签、提及或链接)应用不同的样式,例如颜色、字体或装饰效果。适用于消息应用、笔记工具或社交媒体界面中的富文本输入,通过视觉区分结构化内容来提升用户体验。该包支持所有主要平台,并可无缝集成到现有的 TextEditingController 工作流中。

适合场景

  • 带有样式提及的消息应用
  • 带语法高亮的笔记应用
  • 带有话题标签样式的社交媒体文本字段
  • 自定义富文本编辑器
  • 实时协同编辑

主要特点

  • 通过正则表达式模式进行内联样式
  • 支持多种样式类型
  • 与 TextEditingController 的无缝集成
  • 跨平台兼容性
  • 样式文本的实时预览
  • 可配置的模式匹配

适合对象

  • 开发富文本输入字段的开发者
  • 需要动态文本格式化的应用
  • 包含用户生成内容的项目
  • 使用基于正则表达式的内容标记的团队
  • 需要视觉区分文本模式的 UI

使用建议

  • 需要仔细设计正则表达式以避免性能问题
  • 使用复杂模式时可能会增加内存使用量
  • 样式逻辑必须在跨平台环境下进行测试
  • 不适用于大规模文档编辑
  • 有限的内置模板,适用于常见用例

原始 README

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

rich_text_controller

Pub Version License Pub Points

rich_text_controller is an extended text editing controller for Flutter that supports applying different inline styles based on custom regex patterns. This package simplifies text styling and interaction in Flutter applications, making it easy to create feature-rich text inputs.


Table of Contents

  1. Demo
  2. Features
  3. Installation
  4. Usage
  5. Contributing
  6. License

Demo

Demo GIF

Features

  • Custom Regex Styling: Apply styles dynamically to text patterns.
  • Interactive Callbacks: Define actions for user interactions with matched text.
  • Dynamic Updates: Modify regex patterns on the fly without recreating the controller.
  • IME Composition Support: Smooth handling for languages like Japanese and Chinese.
  • Performance Optimizations: Cached regex for better performance.
  • RichWrapper Widget: A widget for seamless integration with the controller.
  • Fine-grained Configuration: Control deletion behavior, styles, and tap actions for specific matches.

Installation

  1. Add the package to your pubspec.yaml file:
dependencies:
  rich_text_controller: ^[latest_version]
  1. Run the following command to install the package:
flutter pub get
  1. Import the package into your Dart file:
import 'package:rich_text_controller/rich_text_controller.dart';

Usage

Here's a quick example of how to use RichTextController to style specific patterns in a TextField:

Example
import 'package:flutter/material.dart';
import 'package:rich_text_controller/rich_text_controller.dart';

defaultTextStyle(BuildContext context) => TextStyle(color: Colors.black);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('RichTextController Example')),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: TextField(
              controller: RichTextController(
                text: '',
                onMatch: (match, target) {
                  print('Match found: \$match');
                },
                targetMatches: [
                  MatchTargetItem(
                    textStyle: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
                    regex: RegExp(r'#[a-zA-Z0-9_]+'),
                  ),
                  MatchTargetItem(
                    textStyle: TextStyle(color: Colors.green),
                    regex: RegExp(r'@[a-zA-Z0-9_]+'),
                  ),
                ],
              ),
              decoration: InputDecoration(border: OutlineInputBorder()),
            ),
          ),
        ),
      ),
    );
  }
}

Contributing

Contributions are always welcome! Here’s how you can help:

  1. Report bugs or request features via GitHub Issues.
  2. Submit pull requests with well-documented code and examples.
  3. Share your thoughts and ideas to improve the package.

License

Licensed under the MIT License. You are free to use, modify, and distribute this package. See the LICENSE.md file for details.

所属分类

源码仓库

使用此插件的项目