Giter Club home page Giter Club logo

flutter_simple_multiselect's Introduction

Flutter Simple Multiselect

v2.1.0

There are a few multiselect packages for flutter but somehow i haven't found one that is simple like this. It's inspired by the vue multiselect. You can use static or async (server) data and use it as searchable single or multiselect. Everything is customizable.

Note: This package is created on the backbone of Material Tag Editor.

Features

Fetch and search async data directly from server or from static data. Use it for multiselect and single, and use it somehow naturally.

Usage

Add the package to pubspec.yaml

dependencies:
  flutter_simple_multiselect: x.x.x

Import it

import 'package:flutter_simple_multiselect/flutter_simple_multiselect.dart';

Full examples for all three options are in /example folder so please take a look for working version.

Use widget: (Async ultiselect sample)

FlutterMultiselect(
    multiselect: true,
    autofocus: false,
    padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 0),
    enableBorderColor: lineColor,
    focusedBorderColor: lineColor,
    borderRadius: 5,
    borderSize: 1,
    resetTextOnSubmitted: true,
    minTextFieldWidth: 300,
    suggestionsBoxMaxHeight: 300,
    length: selectedItemsAsync.length,
    isLoading: isLoading,
    tagBuilder: (context, index) => SelectTag(
            index: index,
            label: selectedItemsAsync[index]["name"],
            onDeleted: (value) {
            selectedItemsAsync.removeAt(index);
            setState(() {});
            },
        ),
    suggestionBuilder: (context, state, data) {
        var existingIndex = selectedItemsAsync.indexWhere((element) => element["uuid"] == data["uuid"]);
        var selectedData = data;
        return Material(
            onPanDown: (_) {
                var existingIndex = selectedItemsAsync.indexWhere((element) => element["uuid"] == data["uuid"]);
                if (existingIndex >= 0) {
                    selectedItemsAsync.removeAt(existingIndex);
                } else {
                    selectedItemsAsync.add(data);
                }

                state.selectAndClose(data);
                setState(() {});
            }
            child: GestureDetector(
                child: ListTile(
                selected: existingIndex >= 0,
                trailing: existingIndex >= 0 ? const Icon(Icons.check) : null,
                selectedColor: Colors.white,
                selectedTileColor: Colors.green,
                title: Text(selectedData["name"].toString()),
                )));
    },
    suggestionsBoxElevation: 10,
    findSuggestions: (String query) async {
        setState(() {
        isLoading = true;
        });
        var data = await searchFunctionAsync(query);
        setState(() {
        isLoading = false;
        });
        return data;
    })

flutter_simple_multiselect's People

Contributors

vbalagovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flutter_simple_multiselect's Issues

Behavior when chips are selected.

I don't know if it's the expected behavior of this, when you select one or more items, and you unFocus the widget, the hint and TextInput disappears, this is annoying and confusing for the user doesn't have an input.

Item selection not working on web

I am trying to select item from the list, suggestion box closes but item does'nt add. It seems like the list is ignoring pointer.

Flutter versiooon 3.13.9
flutter_simple_multiselect: ^2.0.0

Search query is not used

I wrote something to the text input and it is used in the findSuggestions query. I choose some suggestion and tap the text input again. The same search text is there, but the findSuggerstions query is called with an empty string.

FlutterMultiselect widgets settings used:
multiselect: true,
resetTextOnSubmitted: false,
length: selectedItemsAsync.length
tagBuilder: ...
suggestionBuilder: ...inside I'm not calling state.selectAndClose(data); but just setting selectedItemsAsync.add(data);

Multiple select without close

Hi, is there a possibility to set that the list with suggestions will not close after selecting one of the items? So that the user may choose several options without need to open suggestions (with the same search) over and over again. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.