Giter Club home page Giter Club logo

selectpicker's Introduction

Features

a simple way to create a selector with predefined options for the user

Images

Start All Filter Select
## Getting started

Just import the package.

import 'package:selectpicker/selectpicker.dart';

And transform your list in a list of SelectPickerItem and call the SelectPicker

SelectPicker(
        hint: "Select an item",
        list: [
            SelectPickerItem("Item 1", "1", null),
            SelectPickerItem("Item 1", "2", null),
            SelectPickerItem("Item 1", "3", null),
        ],
        selectFirst: true,
        showId: true,
        onSelect: (value) {
        if (mounted) {
            ScaffoldMessenger.of(context).clearSnackBars();
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value.title.toString())));
          }
        },
        hintSearch: "Search by item description or ID",
        selectPickerInputStyle: SelectPickerInputStyle(),
)

Enjoy.

Example

This a simple screen with usage example. example/example.dart

import 'package:flutter/material.dart';
import 'package:selectpicker/models/select_picker_item.dart';
import 'package:selectpicker/selectpicker.dart';
import 'package:selectpicker/styles/input_style.dart';

class Tela extends StatefulWidget {
  const Tela({super.key});

  @override
  State<Tela> createState() => _TelaState();
}

class _TelaState extends State<Tela> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("SelectPicker", style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.blue,
      ),
      body: Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: SelectPicker(
              hint: "Select an UF",
              list: getStatesPicker(),
              selectFirst: false,
              onSelect: (value) {
                ScaffoldMessenger.of(context).clearSnackBars();
                ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value.title.toString())));
              },
              hintSearch: "Search by UF description or ID",
              selectPickerInputStyle: SelectPickerInputStyle(),
              initialItem: "DF",
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: SelectPicker(
              hint: "Select an item",
              list: [
                SelectPickerItem("Item 1", "1", null),
                SelectPickerItem("Item 1", "2", null),
                SelectPickerItem("Item 1", "3", null),
              ],
              selectFirst: true,
              showId: true,
              onSelect: (value) {
                if (mounted) {
                  ScaffoldMessenger.of(context).clearSnackBars();
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value.title.toString())));
                }
              },
              hintSearch: "Search by item description or ID",
              selectPickerInputStyle: SelectPickerInputStyle(),
            ),
          ),
        ],
      ),
    );
  }

  static List<Uf> getUf() {
    List<Uf> list = [];
    list.add(Uf("Acre", "AC"));
    list.add(Uf("Alagoas", "AL"));
    list.add(Uf("Amapá", "AP"));
    list.add(Uf("Amazonas", "AM"));
    list.add(Uf("Bahia", "BA"));
    list.add(Uf("Ceará", "CE"));
    list.add(Uf("Espírito Santo", "ES"));
    list.add(Uf("Goiás", "GO"));
    list.add(Uf("Maranhão", "MA"));
    list.add(Uf("Mato Grosso", "MT"));
    list.add(Uf("Mato Grosso do Sul", "MS"));
    list.add(Uf("Minas Gerais", "MG"));
    list.add(Uf("Pará", "PA"));
    list.add(Uf("Paraíba", "PB"));
    list.add(Uf("Paraná", "PR"));
    list.add(Uf("Pernambuco", "PE"));
    list.add(Uf("Piauí", "PI"));
    list.add(Uf("Rio de Janeiro", "RJ"));
    list.add(Uf("Rio Grande do Norte", "RN"));
    list.add(Uf("Rio Grande do Sul", "RS"));
    list.add(Uf("Rondônia", "RO"));
    list.add(Uf("Roraima", "RR"));
    list.add(Uf("Santa Catarina", "SC"));
    list.add(Uf("São Paulo", "SP"));
    list.add(Uf("Sergipe", "SE"));
    list.add(Uf("Tocantins", "TO"));
    list.add(Uf("Distrito Federal", "DF"));
    return list;
  }

  static List<SelectPickerItem> getStatesPicker() {
    try {
      List<SelectPickerItem> list = [];
      for (Uf item in getUf()) {
        list.add(SelectPickerItem(item.name, item.uf, item));
      }
      return list;
    } catch (error) {
      return [];
    }
  }
}

class Uf {
  Uf(this.name, this.uf);

  String name;
  String uf;
}

Credits

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.