TextField를 사용하여 간단한 목록에서 값을 검색하고 선택할 수 있도록 해주는 플러터 패키지입니다. 사용자가 입력하는 동안 실시간으로 옵션을 필터링할 수 있는 직관적인 자동 완성 경험을 제공합니다. 가볍고 쉽게 통합할 수 있어, 미리 정의된 데이터에서 빠르게 선택이 필요한 양식이나 입력 필드에 적합합니다. Android, iOS, Web, macOS, Windows, Linux 등 여러 플랫폼을 지원합니다.
사용 사례
검색 가능한 옵션을 가진 폼 입력
대규모 목록에서 빠른 선택
사용자 친화적인 드롭다운 대안
모바일 및 웹 앱에서의 동적 필터링
간소화된 데이터 입력 워크플로우
주요 기능
실시간 검색 필터링
TextField와의 간단한 통합
여러 플랫폼을 지원합니다
경량이며 최소한의 종속성
사용자 정의 가능한 UI 및 스타일링
적합한 대상
검색 가능한 입력을 사용하여 폼을 구축하는 개발자
빠른 데이터 선택이 필요한 앱
크로스플랫폼 애플리케이션
간단함과 성능을 우선시하는 프로젝트
고려 사항
기본적인 리스트 기반 검색에 제한됨
원격 데이터 소스 지원 없음
선택된 값을 수동으로 처리해야 합니다
복잡한 자동 완성 시나리오에 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
flutter_textfield_search
FTFS is a Flutter package which uses a TextField Widget to search and select a value from a list.
It's a simple, lightweight, and fully tested package unlike other "autocomplete" or textfield search
packages. View complete code coverage results in JSON
format here.
Usage
To use this package, add flutter_textfield_search as a dependency in your pubsec.yaml file.
Then include the widget anywhere you would normally use a TextField widget with a String for label,
a List for initialList, and a TextEditingController for controller.
Example MaterialApp using TextFieldSearch Widget
To get the value of the selected option, use addListener on the controller to listen for changes:
@override
void dispose() {
// Clean up the controller when the widget is removed from the
// widget tree.
myController.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
// Start listening to changes.
myController.addListener(_printLatestValue);
}
_printLatestValue() {
print("Textfield value: ${myController.text}");
}
Selecting a List item from a Future List:
TextEditingController myController = TextEditingController();
// create a Future that returns List
Future<List> fetchData() async {
await Future.delayed(Duration(milliseconds: 5000));
List list = [];
String _inputText = myController.text;
// create a list from the text input of three items
// to mock a list of items from an http call
list.add(_inputText + ' Item 1');
list.add(_inputText + ' Item 2');
list.add(_inputText + ' Item 3');
return list;
}
@override
void dispose() {
// Clean up the controller when the widget is removed from the
// widget tree.
myController.dispose();
super.dispose();
}
// used within a MaterialApp (code shortened)
MaterialApp(
home: Scaffold(
body: TextFieldSearch(
label: 'My Label',
controller: myController
future: () {
return fetchData();
}
)
),
)
Selecting an object from a Future List:
TextEditingController myController = TextEditingController();
// create a Future that returns List
// IMPORTANT: The list that gets returned from fetchData must have objects that have a label property.
// The label property is what is used to populate the TextField while getSelectedValue returns the actual object selected
Future<List> fetchData() async {
await Future.delayed(Duration(milliseconds: 3000));
List list = [];
String _inputText = myController.text;
List jsonList = [
{
'label': _inputText + ' Item 1',
'value': 30
},
{
'label': _inputText + ' Item 2',
'value': 31
},
{
'label': _inputText + ' Item 3',
'value': 32
},
];
// create a list of 3 objects from a fake json response
list.add(TestItem.fromJson(jsonList[0]));
list.add(TestItem.fromJson(jsonList[1]));
list.add(TestItem.fromJson(jsonList[2]));
return list;
}
@override
void dispose() {
// Clean up the controller when the widget is removed from the
// widget tree.
myController.dispose();
super.dispose();
}
// used within a MaterialApp (code shortened)
MaterialApp(
home: Scaffold(
body: TextFieldSearch(
label: 'My Label',
controller: myController
future: () {
return fetchData();
},
getSelectedValue: (value) {
print(value); // this prints the selected option which could be an object
}
)
),
)
// Mock Test Item Class
class TestItem {
final String label;
dynamic value;
TestItem({ required this.label, this.value });
factory TestItem.fromJson(Map<String, dynamic> json) {
return TestItem(
label: json['label'],
value: json['value']
);
}
}
Issues
Please email any issues, bugs, or additional features you would like to see built to
arindone@nubeer.io.
Contributing
If you wish to contribute to this package you may fork the repository and make a pull request to
this repository.
Note: Testing by running flutter test --coverage will generate coverage/lcov.info.
Running bash test-coverage.sh will parse the lcov.info file into JSON format. This happens
automatically within the CI/CD pipeline on a pull request to main but it is always good to test
locally.