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

flutter_mentions 封面
插件详情v2.0.1

flutter_mentions

一个简单的 Flutter 输入小部件,可为您的应用添加 @ 提及功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
4060
喜欢数
174
Pub 分数
130

安装插件

flutter pub add flutter_mentions

插件介绍

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

Flutter Mentions 是一个轻量级的 Flutter 包,为文本输入字段添加 @提及 功能,使用户能够在文本中标记他人。它支持实时建议,并可无缝集成到表单或聊天界面中。该组件可自定义,适用于所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。非常适合需要用户标记功能的社交媒体应用、消息平台或协作工具。

适合场景

  • 社交媒体应用
  • 消息接口
  • 协作内容编辑
  • 评论中的用户标记
  • 实时聊天功能

主要特点

  • @mention 建议下拉菜单
  • 跨平台兼容性
  • 可自定义样式
  • 与 TextFormField 的轻松集成
  • 实时提及过滤

适合对象

  • 开发聊天应用的开发者
  • 创建社交平台的团队
  • 需要用户标记的应用程序
  • 文本输入的UI组件
  • 具有跨平台需求的项目

使用建议

  • 需要手动处理提及数据
  • 仅限基本提及逻辑
  • 无内置后端支持
  • 可能需要额外的验证
  • 样式自定义需要代码调整

原始 README

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

📛 Flutter Mentions

A simple flutter input widget to add @ mentions functionality to your app

Install 📦

To use this package, add flutter_mentions as a dependency in your pubspec.yaml file.

You will need to add flutter_mentions to your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  flutter_mentions:

Then, run flutter packages get in your terminal.

Usage 💻

To use this package you must first wrap your top most widget with Portal as this package uses flutter_portal to show the suggestions list.

[Portal], is the equivalent of [Overlay].

This widget will need to be inserted above the widget that needs to render under your overlays.

If you want to display your overlays on the top of everything, a good place to insert that [Portal] is above MaterialApp:

Portal(
  child: MaterialApp(
    ...
  )
);

(works for CupertinoApp too)

This way [Portal] will render above everything. But you could place it somewhere else to change the clip behavior.

Widgets:

FlutterMention

  • mentions: List<Mention> - List of Mention that the user is allowed to triggered.
  • suggestionPosition: SuggestionPosition - Suggestion modal position, can be alligned to [Top] or [Bottom].
  • onMentionAdd: Function(Map<String, dynamic>) - Triggers when the suggestion was added by tapping on suggestion.
  • suggestionListHeight: double - Max height for the suggestion list. Defaults for 300.0.
  • onMarkupChanged: Function(String) - A Functioned which is triggered when ever the input changes but with the markup of the selected mentions.
  • suggestionListDecoration: BoxDecoration - Decoration for the Suggestion list.
  • defaultText: String - Populate your input field with pre-filled text.
  • onSearchChange: Function(String trigger, String value) - Fired only when the input changes & user is searching a mention item.
  • leading: List<Widget> - List of widgets that should be placed before the input.
  • trailing: List<Widget> - List of widgets that should be placed after the input.
  • onSuggestionVisibleChanged: Function(bool) - Triggers when the suggestion list visibility changed.
  • Supports all the other properties that TextField supports.

Mention

  • trigger: String - A single character that will be used to trigger the suggestions.
  • data: List<Map<String, dynamic>> - List of Map to represent the suggestions shown to the user. You need to provide two Required properties id & display both are [String] You can also have any custom properties as you like to build custom suggestion widget (NOTE: this can later be updated to show new or filtered mention list).
  • style: TextStyle - Style for the mention item in Input.
  • matchAll: bool - Should every non-suggestion with the trigger character be matched.
  • disableMarkup: bool - Should the markup generation be disabled for this Mention Item.
  • suggestionBuilder: Widget Function(Map<String, dynamic>) - Build Custom suggestion widget using this builder.
  • markupBuilder: String Function(String trigger, String mention, String value) - Used to define how the mentions markup should be saved.

example, Mention instance

Mention(
  trigger: "#",
  disableMarkup: true,
  style: TextStyle(
    color: Colors.blue,
  ),
  data: [
    {"id": "reactjs", "display": "reactjs"},
    {"id": "javascript", "display": "javascript"},
  ],
  matchAll: true,
)

Example

FlutterMentions(
  key: key,
  suggestionPosition: SuggestionPosition.Top,
  maxLines: 5,
  minLines: 1,
  mentions: [
    Mention(
      trigger: "@",
      style: TextStyle(color: Colors.purple),
      data: [
        {
          "id": "61as61fsa",
          "display": "fayeedP",
          "photo": "https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg"
        },
        {
          "id": "61asasgasgsag6a",
          "display": "khaled",
          "photo": "https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg",
          style: TextStyle(color: Colors.green),
        },
      ],
    )
  ],
),

You can find detailed example in example folder

Frequently asked questions

1. How do I can access to the the editing controller? A. To get the control of TextEditingController just use a Global key more info can be found here #13. This will also allow you to access the text & markupText.

2. How do I search users as I type? A. Just use the onSearchChange to get the currrent search text & make request to the server and later update the data.

3. What is the need of Portal? A. You should check this comment where I mentioned in more detail the reason behind using portal.

Credits 👨🏻‍💻

Found this project useful? ❤️

If you found this project useful, then please consider giving it a ⭐️ on Github and sharing it with your friends via social media.

License ⚖️

API details 📝

See the flutter_mentions.dart for more API details

Issues and feedback 💭

If you have any suggestion for including a feature or if something doesn't work, feel free to open a Github issue for us to have a discussion on it.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。