Version Version

一个高度可定制的多选小部件,具有模糊搜索功能

MultipleSearchSelection<Country>(
        items: countries, // List<Country>
        fieldToCheck: (c) {
          return c.name; // String
        },
        itemBuilder: (country) {
          return Padding(
            padding: const EdgeInsets.all(6.0),
            child: Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(6),
                color: Colors.white,
              ),
              child: Padding(
                padding: const EdgeInsets.symmetric(
                  vertical: 20.0,
                  horizontal: 12,
                ),
                child: Text(country.name),
              ),
            ),
          );
        },
        pickedItemBuilder: (country) {
          return Container(
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: Colors.grey[400]!),
            ),
            child: Padding(
              padding: const EdgeInsets.all(8),
              child: Text(country.name),
            ),
          );
        },
        onTapShowedItem: () {},
        onPickedChange: (items) {},
        onItemAdded: (item) {},
        onItemRemoved: (item) {},
        sortShowedItems: true,
        sortPickedItems: true,
        fuzzySearch: FuzzySearch.jaro,
        itemsVisibility: ShowedItemsVisibility.alwaysOn,
        title: Text(
          'Countries',
          style: kStyleDefault.copyWith(
            fontSize: 22,
            fontWeight: FontWeight.bold,
          ),
        ),
        showSelectAllButton: true,
        searchItemTextContentPadding:
            const EdgeInsets.symmetric(horizontal: 10),
        maximumShowItemsHeight: 200,
      )

MultipleSearchSelection<T>.creatable

MultipleSearchSelection<T>.creatable 构造函数现在可以在搜索结果未返回任何结果时创建新项。它采用新的必需参数 createOptions,例如

// [T] here is [Country]
createOptions: OptionItems<Country>(
    // You need to create and return the item you want to add since [T] is not always [String].
    createItem: (text) {
        return Country(name: text, iso: text);
    },
    // A callback when the item is succesfully created.
    onItemCreated: (c) => print('Country ${c.name} created'),
    // Create item Widget that appears instead of no results.
    createItemBuilder: (text) => Align(
        alignment: Alignment.centerLeft,
            child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text('Create "$text"'),
            ),
        ),
    // Whether you want to pick the newly created item or just add it to your list. Defaults to false.
    pickCreatedItem: true,
),

显示的项行为

始终显示 键入时 切换
Always on On type Toggle

问题 / 功能

发现 Bug 或想要新功能? 在项目的 Github 仓库 中打开一个 issue。

GitHub

查看 Github