simple_search_dropdown 1.0.1 copy "simple_search_dropdown: ^1.0.1" to clipboard
simple_search_dropdown: ^1.0.1 copied to clipboard

A dropdown that offers a search bar, multiple and single selections.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'package:flutter/material.dart';
import 'package:simple_search_dropdown/simple_search_dropdown.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<String> listitems = ['Lorenzo', 'É', 'Muito', 'Bonito'];
  List<String> selectedMultipleItems = [];
  String? selectedSingleItem;

  void removeItem(String item) {
    setState(() {
      listitems.remove(item);
    });
  }

  void addItem(String item) {
    setState(() {
      listitems.add(item);
    });
  }

  void updateSelectedItems(List<String> newSelectedItems) {
    setState(() {
      selectedMultipleItems = newSelectedItems;
    });
  }

  void updateSelectedItem(String newSelectedItem) {
    setState(() {
      selectedSingleItem = newSelectedItem;
    });
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SearchDropDown(
              listItens: listitems,
              onDeleteItem: removeItem, 
              onAddItem: addItem,
              addMode: true,
              deleteMode: true,
              updateSelectedItem: updateSelectedItem,
            ),
            const SizedBox(height: 20,),
            MultipleSearchDropDown(
              listItems: listitems,
              onDeleteItem: removeItem, 
              onAddItem: addItem,
              addMode: true,
              deleteMode: true,
              selectedItems: selectedMultipleItems,
              updateSelectedItems: updateSelectedItems,
            ),
            const SizedBox(height: 20,),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextButton(
                  onPressed: (){print(selectedSingleItem);}, 
                  child: const Text('Print Single Result')
                ),
                const SizedBox(width: 10,),
                TextButton(
                  onPressed: (){print(selectedMultipleItems);}, 
                  child: const Text('Print Multiple Result')
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
5
likes
0
pub points
67%
popularity

Publisher

unverified uploader

A dropdown that offers a search bar, multiple and single selections.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, stringr

More

Packages that depend on simple_search_dropdown