from_filed_drop_down 1.1.3

SDKflutter
Platformandroidioswindowslinuxmacosweb

A customizable dropdown widget for Flutter with advanced styling, search functionality, and dynamic data handling.

from_filed_drop_down 🛠️

A highly customizable dropdown widget for Flutter with powerful features like search, API integration, custom UI support, and validation.


Features

  • Display static items or fetch them dynamically via APIs.
  • Fully customizable dropdown appearance using BoxDecoration and custom item builders.
  • Support for readonly and searchable dropdowns, along with additional customization options.
  • Easy integration with TextFormField for validation and decoration.
  • Advanced cursor styling for an enhanced user interface.
  • Seamless integration of an add-button for custom functionality.
  • Flexible search and filter options, supporting both local and API-based data.

Installation

1.Add the latest version of package to your pubspec.yaml (and run flutter pub get):

dependencies:
  from_filed_drop_down: latest_version

2.Import the package and use it in your Flutter App.

import 'package:animated_custom_dropdown/custom_dropdown.dart';

Example usage

1.Basic FromFiledDropDown

import 'package:flutter/material.dart';
import 'package:from_filed_drop_down/from_filed_drop_down.dart';
final countryController = OverlayPortalController();
final countryTextController = TextEditingController();

String? selectedItem;
List<String> itemList = ["item","item 2","item 3","item 4","item 5","item 6"];

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FromFiledDropDown<String>(
        controller: countryController,
        textController: countryTextController,
        item : itemList,
        textStyle: const TextStyle(
            fontSize: 12,
            fontWeight: FontWeight.w400
        ),
        filedDecoration: const InputDecoration(),
        onChanged: (String? value) {},
        listItemBuilder: (context, item, isSelected, onItemSelect) {
          return Text(
            item,
            style: TextStyle(
                fontSize: 12,
                color: isSelected ? Colors.white : Colors.black,
                fontWeight: FontWeight.w400
            ),
          );
        },
        selectedItemBuilder: (context, {item}) {
          return Text(
            item!,
            style: const TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w400
            ),
          );
        },
      ),
    );
  }
}

2.FromFiledDropDown with a Custom Add Button

The addButton property lets you define a custom widget to trigger additional actions, such as opening a dialog box, navigating to another screen, or performing user-defined functionality.

class DropDownClass extends StatelessWidget {
  const DropDownClass({super.key});
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: Column(
        children: [
          FromFiledDropDown<String>(
            item : itemList,
            controller: countryController,
            canShowButton: true,
            addButton:  InkWell(
              onTap: () {
                // add your event's
              },
              child: Container(
                height: 40,
                padding: const EdgeInsets.all(10),
                decoration:BoxDecoration(
                  color: Colors.green,
                  borderRadius: BorderRadius.circular(2),
                ),
                child: const Row(
                  children: [
                    Expanded(
                      child: Text(
                          "Add",
                          maxLines: 1,
                          textAlign:TextAlign.start,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(color: Colors.white)
                      ),
                    ),
                    Icon(
                      Icons.add,
                      color: Colors.white,
                    )
                  ],
                ),
              ),
            ),
            textController: countryTextController,
            textStyle: const TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w400
            ),
            menuDecoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(4),
                border: Border.all(
                    color: Colors.blueAccent
                )
            ),
            filedDecoration: const InputDecoration(),
            onChanged: (String? value) {},
            listItemBuilder: (context, item, isSelected, onItemSelect) {
              return Text(
                item,
                style: TextStyle(
                    fontSize: 12,
                    color: isSelected ? Colors.white : Colors.black,
                    fontWeight: FontWeight.w400
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

3.FromFiledDropDown with Dynamic Search or API Integration

Advanced usage example for fetching dropdown items dynamically from an API.

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

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: Column(
        children: [
          FromFiledDropDown<String>(
            controller: countryController,
            textController: countryTextController,
            initialItem: selectedItem,
            item : itemList,
            onTap: () async{
              // example API, or return your API list.
              return itemList;
            },
            textStyle: const TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w400
            ),
            filedDecoration: InputDecoration(
                contentPadding: const EdgeInsets.all(10),
                errorStyle:const TextStyle(fontSize: 12,color: Colors.red,),
                fillColor: Colors.white,
                hintStyle: TextStyle(color: Colors.grey.shade800),
                filled: true,
                focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4),
                    borderSide:  const BorderSide(
                        color: Colors.blueAccent
                    )
                ),
                enabledBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4),
                    borderSide: const BorderSide(
                        color: Colors.blueAccent
                    )
                ),
                errorBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4),
                    borderSide: const BorderSide(
                        color: Colors.red
                    )
                ),
                focusedErrorBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(4),
                    borderSide: const BorderSide(
                        color: Colors.red
                    )
                )
            ),
            onChanged: (String? value) {},
            onSearch: (value) async {
              // We can call your API and search from it. Also, I can implement local search in your static list.
              return itemList.where((element) {
                return element.contains(value.toLowerCase());
              }).toList();
            },
            listItemBuilder: (context, item, isSelected, onItemSelect) {
              return Text(
                item,
                style: TextStyle(
                    fontSize: 12,
                    color: isSelected ? Colors.white : Colors.black,
                    fontWeight: FontWeight.w400
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

Properties

PropertyTypeDescription
itemList<T>?List of dropdown items to display.
filedReadOnlyboolMakes TextFormField readonly.
readOnlyboolMakes dropdown readonly.
initialItemT?Initial value for the dropdown.
isApiLoadingboolIndicates if the API is loading.
showCursorbool?Toggles the cursor visibility.
cursorColorColor?Changes the cursor color.
cursorHeightdouble?Sets the cursor height.
cursorWidthdouble?Sets the cursor width.
cursorRadiusRadius?Sets the cursor border radius.
cursorErrorColorColor?Sets the cursor error color.
textStyleTextStyleStyles the search or selected text.
loaderWidgetWidget?Custom widget to show during API loading.
focusNodeFocusNode?Manages focus for searchable dropdowns.
errorMessageText?Custom error message when no items are found.
overlayHeightdouble?Height of the dropdown overlay.
addButtonWidget?Adds a custom button for additional functionality.
textControllerTextEditingControllerController for the TextFormField.
onChangedFunction(T? value)Callback triggered when an item is selected.
menuDecorationBoxDecoration?Custom decoration for the dropdown menu.
filedDecorationInputDecorationDecoration for the TextFormField.
onTapFuture<List<T>> Function()Loads items dynamically for the dropdown.
autovalidateModeAutovalidateMode?Enables validation listener when items change.
controllerOverlayPortalControllerControls dropdown visibility programmatically.
listItemBuilderListItemBuilder<T>Custom builder for dropdown items.
selectedItemBuilderSelectedItemBuilder<T?>?Custom builder for the selected item.
onSearchFuture<List<T>> Function(String)Callback for API-based search functionality.
listPaddingEdgeInsets?Sets padding for the list view.
menuMarginEdgeInsets?Sets margin for the dropdown item container.
canShowButtonboolToggles the visibility of the add button.
textAlignTextAlignAligns the text in the search field.
keyboardTypeTextInputType?Sets the input type for the TextFormField.
maxLineint?Limits the maximum number of text lines.
maxLengthint?Limits the maximum number of characters.
inputFormattersList<TextInputFormatter>?Applies input formatting rules to the TextFormField.
validatorString? Function(String?)Validates the dropdown value.