apptomate_custom_dropdown

This CustomDropDown widget is a reusable, customizable dropdown widget in Flutter that allows you to create dropdown menus with enhanced styling and behavior.

Platform


πŸ“ Description

apptomate_custom_dropdown is a reusable, customizable dropdown widget in Flutter that allows you to create dropdown menus with enhanced styling and behavior. It extends StatelessWidget and supports various customizations, including icon, text style, shadow, and elevation.


πŸš€ Features

βœ… Customizable dropdown menu options βœ… Supports dynamic data type (T) βœ… Customizable icon, border, color, and text style βœ… Allows mapping of display values βœ… Elevation and shadow customization βœ… Flexible width and height


πŸ“² Installation

Add the dependency to your pubspec.yaml:

dependencies:
  apptomate_custom_dropdown: ^0.0.1

Basic Example

import 'package:flutter/material.dart';

class Example extends StatelessWidget {
  final List<String> options = ['Option 1', 'Option 2', 'Option 3'];
  String? selectedOption;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Custom DropDown Example')),
      body: Center(
        child: CustomDropDown<String>(
          items: options,
          value: selectedOption,
          onChanged: (value) {
            selectedOption = value;
            print("Selected: $value");
          },
          hint: 'Choose an option',
          backgroundColor: Colors.white,
          borderColor: Colors.blue,
          borderRadius: 12.0,
          elevation: 4.0,
          shadowColor: Colors.grey,
          dropDownIcon: Icon(Icons.arrow_drop_down, color: Colors.blue),
          dropDownTextStyle: TextStyle(color: Colors.black, fontSize: 16),
          selectedDropdownTextStyle: TextStyle(color: Colors.red, fontSize: 16),
        ),
      ),
    );
  }
}

βœ… With displayMapper


class Option {
  final int id;
  final String name;

  Option(this.id, this.name);
}

final List<Option> options = [
  Option(1, 'Option A'),
  Option(2, 'Option B'),
];

CustomDropDown<Option>(
  items: options,
  value: selectedOption,
  onChanged: (value) {
    setState(() {
      selectedOption = value;
    });
  },
  displayMapper: (option) => option.name,
);

🎨 Styling Example


CustomDropDown<String>(
  items: ['Item 1', 'Item 2', 'Item 3'],
  value: 'Item 1',
  onChanged: (value) {},
  backgroundColor: Colors.white,
  borderColor: Colors.blue,
  borderRadius: 16.0,
  elevation: 4.0,
  shadowColor: Colors.grey,
  dropDownIcon: Icon(Icons.arrow_drop_down, color: Colors.blue),
  dropDownTextStyle: TextStyle(fontSize: 14, color: Colors.black),
  selectedDropdownTextStyle: TextStyle(fontSize: 14, color: Colors.red),
);

βœ… Best Practices

βœ”οΈ Use displayMapper when working with objects. βœ”οΈ Keep onChanged non-null for proper state updates. βœ”οΈ Ensure items list is not empty. βœ”οΈ Keep value within the range of items to avoid errors.


πŸš€ Complete Code


CustomDropDown<String>(
  items: ['Item 1', 'Item 2', 'Item 3'],
  value: 'Item 1',
  onChanged: (value) {},
  backgroundColor: Colors.white,
  borderColor: Colors.blue,
  borderRadius: 16.0,
  elevation: 4.0,
  shadowColor: Colors.grey,
  dropDownIcon: Icon(Icons.arrow_drop_down, color: Colors.blue),
  dropDownTextStyle: TextStyle(fontSize: 14, color: Colors.black),
  selectedDropdownTextStyle: TextStyle(fontSize: 14, color: Colors.red),
);