搜尋套件、儲存庫與 APP 分類

套件詳情v0.12.3

textfield_search

一個全新的 Flutter 套件,使用 TextField 從簡單清單中搜尋並選擇其值。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3390
喜歡數
140
Pub 分數
150

安裝套件

flutter pub add textfield_search

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,讓使用者能使用 TextField 從簡單清單中搜尋並選擇值。它提供直覺的自動完成體驗,支援使用者輸入時即時過濾選項。此套件輕量且易於整合,非常適合需要從預設資料中快速選擇的表單或輸入欄位。支援多個平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

適用情境

  • 具有可搜尋選項的表單輸入
  • 從大型列表中快速選擇
  • 使用者友善的下拉選單替代方案
  • 行動與網頁應用中的動態過濾
  • 簡化資料輸入工作流程

主要特色

  • 即時搜尋過濾
  • 與 TextField 的簡單整合
  • 支援多個平台
  • 輕量且依賴極少
  • 可自訂的 UI 與樣式

適合對象

  • 使用可搜尋輸入建構表單的開發者
  • 需要快速資料選擇的應用程式
  • 跨平台應用程式
  • 重視簡單性與效能的專案

使用建議

  • 僅限基於清單的基本搜尋
  • 不支援遠端資料來源
  • 需要手動處理所選值
  • 不適用於複雜的自動補全情境

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_textfield_search

Build and Test

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.

Example

Import the package.

`import 'package:flutter_textfield_search/textfield_search.dart'`;

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

    const label = "Some Label";
    const dummyList = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];
    TextEditingController myController = TextEditingController();
    MaterialApp(
      home: Scaffold(
      body: TextFieldSearch(initialList: dummyList, label: label, controller: myController)
      ),
    )

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.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。