搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案