Giter Club home page Giter Club logo

flutter_mentions's Introduction

๐Ÿ“› 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.
  • 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.

flutter_mentions's People

Contributors

fayeed avatar erjanmx avatar imhafeez avatar krishnakumarcn avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.