Orientação gerada a partir de informações públicas. Apenas para referência.
Um widget Flutter que habilita funcionalidade de autocomplete baseada em gatilhos, permitindo que os usuários sugiram e selecionem opções dinamicamente quando caracteres específicos (como @ ou #) são digitados. Ideal para aplicativos de mídia social, interfaces de mensagens ou qualquer campo de entrada que exija sugestões contextuais. O pacote suporta múltiplos gatilhos e se integra perfeitamente em plataformas Android, iOS, Web, macOS, Windows e Linux.
Casos de uso
marcação em redes sociais
menções de aplicativo de mensagens
Sugestões de hashtags
Melhorias de entrada de formulário
Busca em tempo real em campos de texto
Principais recursos
Suporte para múltiplos gatilhos
Compatibilidade multiplataforma
Modelos de sugestão personalizáveis
Integração fácil com TextFields
Leve e eficiente
Indicado para
Desenvolvedores construindo aplicativos de bate-papo ou sociais
Aplicativos que precisam de autocompletar consciente do contexto
Projetos que exigem tratamento de entrada multi-gatilho
Equipes usando Flutter para desenvolvimento full-stack
Considerações
Requer configuração manual para gatilhos personalizados
Limitado a contextos de entrada de texto
Pode ser necessário estilização adicional para interfaces de usuário complexas
Depende de gerenciamento externo de estado para dados dinâmicos
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Multi Trigger Autocomplete
A flutter widget to add trigger based autocomplete functionality to your app.
Show some ❤️ and star the repo to support the project
Installation
Add the following to your pubspec.yaml and replace [version] with the latest version:
MultiTriggerAutocomplete(
optionsAlignment: OptionsAlignment.topStart,
autocompleteTriggers: [
// Add the triggers you want to use for autocompleteAutocompleteTrigger(
trigger: '@',
optionsViewBuilder: (context, autocompleteQuery, controller) {
returnMentionAutocompleteOptions(
query: autocompleteQuery.query,
onMentionUserTap: (user) {
final autocomplete = MultiTriggerAutocomplete.of(context);
return autocomplete.acceptAutocompleteOption(user.id);
},
);
},
),
AutocompleteTrigger(
trigger: '#',
optionsViewBuilder: (context, autocompleteQuery, controller) {
returnHashtagAutocompleteOptions(
query: autocompleteQuery.query,
onHashtagTap: (hashtag) {
final autocomplete = MultiTriggerAutocomplete.of(context);
return autocomplete
.acceptAutocompleteOption(hashtag.name);
},
);
},
),
AutocompleteTrigger(
trigger: ':',
optionsViewBuilder: (context, autocompleteQuery, controller) {
returnEmojiAutocompleteOptions(
query: autocompleteQuery.query,
onEmojiTap: (emoji) {
final autocomplete = MultiTriggerAutocomplete.of(context);
return autocomplete.acceptAutocompleteOption(
emoji.char,
// Passing false as we don't want the trigger [:] to// get prefixed to the option in case of emoji.
keepTrigger: false,
);
},
);
},
),
],
// Add the text field widget you want to use for autocomplete
fieldViewBuilder: (context, controller, focusNode) {
returnPadding(
padding: constEdgeInsets.all(8.0),
child: ChatMessageTextField(
focusNode: focusNode,
controller: controller,
),
);
},
),
Demo
Mention Autocomplete
Hashtag Autocomplete
Emoji Autocomplete
Customization
MultiTriggerAutocomplete
MultiTriggerAutocomplete(
// Defines the autocomplete trigger that will be used to match the// text.
autocompleteTriggers: autocompleteTriggers,
// Defines the alignment of the options view relative to the// fieldView.//// By default, the options view is aligned to the bottom of the// fieldView.
optionsAlignment: OptionsAlignment.topStart,
// Defines the width to make the options as a multiple of the width// of the fieldView.//// Setting this to 1 makes the options view width matches the width// of the fieldView.//// Use null to remove this constraint.
optionsWidthFactor: 1.0,
// Defines the duration of the debounce period for the// [TextEditingController].//// This is the time between the last character typed and the matching// is performed.
debounceDuration: constDuration(milliseconds: 350),
// Defines the initial value to set in the internal// [TextEditingController].//// This value will be ignored if [TextEditingController] is provided.
initialValue: constTextEditingValue(text: 'Hello'),
// Defines the [TextEditingController] that will be used for the// fieldView.//// If this parameter is provided, then [focusNode] must also be// provided.
textEditingController: TextEditingController(text: 'Hello'),
// Defines the [FocusNode] that will be used for the fieldView.//// If this parameter is provided, then [textEditingController] must// also be provided.
focusNode: FocusNode(),
// Defines the fieldView that will be used to input the text.//// By default, a [TextFormField] is used.
fieldViewBuilder: (context, controller, focusNode) {
returnTextField(
controller: controller,
focusNode: focusNode,
);
},
),
AutocompleteTrigger
AutocompleteTrigger(
// The trigger string/character that will be used to trigger the// autocomplete.
trigger: '@',
// If true, the [trigger] should only be recognised at// the start of the input text.//// valid example: "@luke hello"// invalid example: "Hello @luke"
triggerOnlyAtStart: false,
// If true, the [trigger] should only be recognised after// a space.//// valid example: "@luke", "Hello @luke"// invalid example: "Hello@luke"
triggerOnlyAfterSpace: true,
// A minimum number of characters can be provided to only show// suggestions after the user has input enough characters.//// example:// "Hello @l" -> Shows zero suggestions.// "Hello @lu" -> Shows suggestions for @lu.
minimumRequiredCharacters: 2,
// The options view builder is used to build the options view// that will be shown when the [trigger] is detected.
optionsViewBuilder: (context, autocompleteQuery, controller) {
returnMentionAutocompleteOptions(
query: autocompleteQuery.query,
onMentionUserTap: (user) {
// Accept the autocomplete option.final autocomplete = MultiTriggerAutocomplete.of(context);
return autocomplete.acceptAutocompleteOption(user.id);
},
);
},
)