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

fluttertagger 封面
插件详情v2.3.2

fluttertagger

一个 Flutter 包,可扩展 TextField 以提供标记功能(用户提及、话题标签等)。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.5万
喜欢数
96
Pub 分数
160

安装插件

flutter pub add fluttertagger

插件介绍

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

FlutterTagger 是一个 Flutter 包,可为 TextFields 增强标签功能,使用户能够输入和管理提及或话题标签。它提供了一种无缝的方式,实时识别、高亮并交互 tagged text。该包支持 Android、iOS、Web、macOS、Windows 和 Linux 多个平台,非常适合社交媒体和消息应用。通过可自定义的样式和事件处理,开发者可以轻松将标签建议和交互集成到他们的应用中。

适合场景

  • 社交媒体评论区
  • 用户提及系统
  • 帖子中的话题标签跟踪
  • 实时聊天应用
  • 表单中的内容标记
  • 交互式文本编辑

主要特点

  • 实时标签识别
  • 可自定义标签样式
  • 建议下拉菜单集成
  • 跨平台兼容性
  • 标签操作的事件回调
  • 可扩展的 TextField 包装器

适合对象

  • 开发社交功能的开发者
  • 需要用户标记的应用程序
  • 消息或论坛应用
  • 用于内容创作工具的插件
  • 需要交互式文本输入的项目

使用建议

  • 需要仔细处理文本选择
  • 可能需要自定义逻辑来处理复杂的标签解析
  • 大型标签列表的性能影响
  • 有限的内置验证
  • 依赖于正确的状态管理
  • 不支持超出标记以外的富文本编辑

原始 README

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

FlutterTagger

FlutterTagger

likes pub points code coverage

FlutterTagger is a Flutter package that allows for the extension of TextFields to provide tagging capabilities. A typical use case is in social apps where user mentions and hashtags features are desired.

Install 🚀

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  fluttertagger: ^2.3.2

Import the package in your project 📥

import 'package:fluttertagger/fluttertagger.dart';

Usage 🏗️

FlutterTagger(
          controller: flutterTaggerController,
          onSearch: (query, triggerCharacter) {
              //perform search
          },
          //characters that can trigger a search and the styles
          //to be applied to their tagged results in the TextField
          triggerCharacterAndStyles: const {
            '@': TextStyle(color: Colors.pinkAccent),
            '#': TextStyle(color: Colors.blueAccent),
          },
          //this will cause the onSearch callback to be invoked
          //immediately a trigger character is detected.
          //The default behaviour defers the onSearch invocation
          //until a searchable character has been entered after
          //the trigger character.
          triggerStrategy: TriggerStrategy.eager,
          overlay: SearchResultView(),
          builder: (context, textFieldKey) {
              //return a TextField and pass it `textFieldKey`
              return TextField(
                    key: textFieldKey,
                    controller: flutterTaggerController,
                    suffix: IconButton(
                      onPressed: () {
                        //get formatted text from controller
                        final text = flutterTaggerController.formattedText;

                        //perform send action...

                        FocusScope.of(context).unfocus();
                        flutterTaggerController.clear();
                      },
                    icon: const Icon(
                      Icons.send,
                      color: Colors.redAccent,
                    ),
                  ),
                );
          },
        )

Here's how trigger a search by updating the controller directly instead of typing into a keyboard:

FlutterTagger(
          controller: flutterTaggerController,
          onSearch: (query, triggerCharacter) {
              //perform search
          },
          //characters that can trigger a search and the styles
          //to be applied to their tagged results in the TextField
          triggerCharacterAndStyles: const {
            '@': TextStyle(color: Colors.pinkAccent),
            '#': TextStyle(color: Colors.blueAccent),
          },
          overlay: SearchResultView(),
          builder: (context, textFieldKey) {
              // return a TextField and pass it `textFieldKey`
              return TextField(
                    key: textFieldKey,
                    controller: flutterTaggerController,
                    suffix: IconButton(
                      onPressed: () {
                        // get formatted text from controller
                        String text = flutterTaggerController.formattedText;

                        // append a trigger character to activate the search context
                        flutterTaggerController.text = text += '#';

                        // update text selection
                        flutterTaggerController.selection = TextSelection.fromPosition(
                          TextPosition(offset: flutterTaggerController.text.length),
                        );

                        // append other characters to trigger search
                        flutterTaggerController.text = text += 'f';

                        // update text selection
                        flutterTaggerController.selection = TextSelection.fromPosition(
                          TextPosition(offset: flutterTaggerController.text.length),
                        );

                        // then call formatTags on the controller to preserve formatting
                        flutterTaggerController.formatTags();
                      },
                    icon: const Icon(
                      Icons.send,
                      color: Colors.redAccent,
                    ),
                  ),
                );
          },
        )

Explore detailed example demo here.

Demo 📷

Example demo

Contributions 🫱🏾‍🫲🏼

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。