특정 문자(@ 또는 # 등)를 입력할 때 사용자가 옵션을 동적으로 제안하고 선택할 수 있도록 해주는 트리거 기반 자동 완성 기능을 제공하는 플러터 위젯입니다. 소셜 미디어 앱, 메시징 인터페이스 또는 맥락 기반 제안이 필요한 모든 입력 필드에 적합합니다. 이 패키지는 여러 트리거를 지원하며 안드로이드, iOS, 웹, macOS, Windows, 리눅스 플랫폼과 원활하게 통합됩니다.
사용 사례
소셜 미디어 태그
메시징 앱 언급
해시태그 제안
폼 입력 개선
텍스트 필드에서 실시간 검색
주요 기능
다중 트리거 지원
크로스 플랫폼 호환성
사용자 정의 가능한 제안 템플릿
텍스트 필드와의 간편한 통합
경량이고 성능이 뛰어남
적합한 대상
채팅 또는 소셜 앱을 구축하는 개발자
상황 인식 자동 완성 기능이 필요한 앱
다중 트리거 입력 처리가 필요한 프로젝트
플러터를 사용하여 풀스택 개발을 하는 팀
고려 사항
사용자 정의 트리거를 수동으로 설정해야 합니다
텍스트 입력 컨텍스트에 한정
복잡한 UI를 위해 추가 스타일링이 필요할 수 있습니다
동적 데이터를 위해 외부 상태 관리에 의존합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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);
},
);
},
)