Pakete, Repositories und App-Kategorien suchen

GitHub-Repositorysharmajatin1997/dropdown_model_list

dropdown_model_list

sharmajatin1997/dropdown_model_list open-source repository details.

Projektcover von dropdown_model_list
Sterne
5
Forks
3
Letzter Push (UTC)
29.07.2025
Projektstatus
Aktiv

Original-README

Englischer Projektschnappschuss. Aktuelle Inhalte auf GitHub.

Flutter DropDown Model List

DropDown_Model_list

Features

Flexible DropDown Model List works with a simple model list and Easy to use & customized. In DropDown Model List Feature:-

  • Single Selection
  • Single Selection With Search
  • Multiple Selection
  • Radio Button Selection

# Installation
  1. Add the latest version of package to your pubspec.yaml (and dart pub get):
dart
  dependencies:
    flutter:
      sdk: flutter
    dropdown_model_list: latest
  1. Import the package and use it in your App.

Usage Example

import 'package:dropdown_model_list/dropdown_model_list.dart';

Example of Single Selection DropDown

import 'package:dropdown_model_list/drop_down/select_drop_list.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

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

  @override
  State<SingleSelection> createState() => _SingleSelectionPageState();
}

class _SingleSelectionPageState extends State<SingleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  OptionItems<UserModel>? selectedUser;
  late DropdownListModel<UserModel> userDropdown;

  // Define one reusable placeholder
  final OptionItems<UserModel> placeholderOption = OptionItems(model: null, displayTitle: "Choose user");

  @override
  void initState() {
    super.initState();
    // Start with placeholder shown
    selectedUser = placeholderOption;

    // Only actual users in dropdown
    userDropdown = DropdownListModel<UserModel>(
      users.map((u) => OptionItems<UserModel>(
        model: u,
        displayTitle: u.title!,
      )).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Single Selection DropDown'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            /// Dropdown
            SelectDropList<UserModel>(
              itemSelected: selectedUser,
              dropListModel: userDropdown,
              onOptionSelected: (optionItem) {
                setState(() {
                  selectedUser = optionItem;
                });
              },
              hintText: "Choose user",
              showArrowIcon: true,
              height: 50,
              arrowColor: Colors.black,
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
            ),

            const SizedBox(height: 20),

            /// Clear button
            ElevatedButton(
              onPressed: () {
                setState(() {
                  selectedUser = placeholderOption; // 👈 not in list, but shown
                });
              },
              child: const Text("Clear Selected User"),
            )
          ],
        ),
      ),
    );
  }
}
            

Image of Single Selection DropDown

single_selection

Example of Search DropDown

import 'package:dropdown_model_list/drop_down/search_drop_list.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

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

  @override
  State<SearchSingleSelection> createState() => _SearchSingleSelectionPageState();
}

class _SearchSingleSelectionPageState extends State<SearchSingleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  OptionItemsSearch<UserModel>? selectedUser;
  late DropdownSearchListModel<UserModel> userDropdown;

  // Placeholder used to reset the dropdown
  final OptionItemsSearch<UserModel> placeholderOption =
  OptionItemsSearch(model: null, displayTitle: "Choose user");

  @override
  void initState() {
    super.initState();
    selectedUser = placeholderOption;

    userDropdown = DropdownSearchListModel<UserModel>(
      users
          .map((u) =>
          OptionItemsSearch<UserModel>(model: u, displayTitle: u.title ?? ''))
          .toList(),
    );
  }

  void _onClearSelection() {
    setState(() {
      selectedUser = placeholderOption;
    });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Search DropDown'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            /// Custom Search Dropdown
            SearchDropList<UserModel>(
              itemSelected: selectedUser,
              dropListModel: userDropdown,
              onOptionSelected: (optionItem) {
                setState(() {
                  selectedUser = optionItem;
                });
              },
              hintText: "Choose user",
              showArrowIcon: true,
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
              showClearButton: true,
              onClear: _onClearSelection,
              showBorder: false,
              enable: true,
              borderSize: 1,
            ),

            const SizedBox(height: 20),

            /// Clear Button (optional if showClearButton is used)
            ElevatedButton(
              onPressed: _onClearSelection,
              child: const Text("Clear Selected User"),
            )
          ],
        ),
      ),
    );
  }
}

Image of Search DropDown

search_dropdown

Example of Search DropDown with Multiple selection

import 'package:dropdown_model_list/drop_down/multiple_selection_search.dart';
import 'package:example/model/userModel.dart';
import 'package:flutter/material.dart';

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

  @override
  State<SearchMultipleSelection> createState() =>
      _SearchMultipleSelectionPageState();
}

class _SearchMultipleSelectionPageState extends State<SearchMultipleSelection> {
  final users = [
    UserModel(id: '1', title: 'Alice'),
    UserModel(id: '2', title: 'Bob'),
    UserModel(id: '3', title: 'Charlie'),
  ];

  late MultiDropdownSearchListModel<UserModel> userDropdown;

  // State for selected users
  List<OptionItemsMultiSearch<UserModel>> selectedUsers = [];

  @override
  void initState() {
    super.initState();

    userDropdown = MultiDropdownSearchListModel<UserModel>(
      users
          .map((u) => OptionItemsMultiSearch<UserModel>(
        model: u,
        displayTitle: u.title ?? '',
      ))
          .toList(),
    );
  }

  void _onClearSelection() {
    setState(() {
      selectedUsers.clear();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Search DropDown With Multiple selection'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            /// Custom Search Dropdown
            MultipleSelectionSearchDropList<UserModel>(
              dropListModel: userDropdown,
              hintText: "Choose user",
              showArrowIcon: true,
              height: 60,
              enableSearch: true, //If you hide search field set false but default its true
              textColorTitle: Colors.black,
              textColorItem: Colors.black,
              dropboxColor: Colors.white,
              dropBoxBorderColor: Colors.grey,
              scrollThumbColor: Colors.blue,
              showClearButton: true,
              onClear: _onClearSelection,
              showBorder: false,
              enable: true,
              borderSize: 1,
              // 👇 Track selected items
              selectedItems: selectedUsers,
              // 👇 Handle new selections
              onOptionsSelected: (List<OptionItemsMultiSearch<UserModel>> value) {
                setState(() {
                  selectedUsers = value;
                });
              },
            ),

            const SizedBox(height: 20),

            ElevatedButton(
              onPressed: _onClearSelection,
              child: const Text("Clear Selected User"),
            ),

            const SizedBox(height: 20),

            /// Display selected values
            const Text(
              "Selected Users:",
              style: TextStyle(fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 10),
            ...selectedUsers.map((user) => Text(user.displayTitle)),
          ],
        ),
      ),
    );
  }
}

Image of Search DropDown with Multiple selection

search_with_multiselection

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Jatin Sharma GitHub avatar
GitHub-Autor

Jatin Sharma ↗

Hello, I am a skilled Flutter and Android developer with experience in designing, developing, and deploying mobile applications.

SprachenDartHTMLSwiftKotlinObjective-C

Von diesem Repository veröffentlichte Pakete

Verwendete Abhängigkeiten

Abhängigkeiten 3 Einträge

  • flutter{"sdk":"flutter"}
  • flutter_testEntwicklung{"sdk":"flutter"}
  • flutter_lintsEntwicklung^5.0.0

Wie wähle ich ein passendes Repository?

Nach Anwendungsfall filtern, Aktivität vergleichen und vor der Nutzung das Originalprojekt prüfen.

  1. Nach Name, Autor oder Beschreibung suchen und nach Thema eingrenzen.
  2. Sterne, Forks und letzte Pushes vergleichen. Sterne zeigen Interesse, garantieren aber keine Qualität.
  3. Vor der Nutzung README, Lizenz und Issues auf GitHub prüfen.

Quellen und Pflege

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗