gt_dropdown
A highly customizable and feature-rich dropdown widget library for Flutter, offering seamless integration with forms, validation, search, animations, and extensive styling options. Features dedicated Material 3 and Cupertino implementations with platform-adaptive switching.
Features
- ✅ Platform-Adaptive: Automatic switching between Material 3 and native Cupertino UI (
AdaptiveDropdown) - ✅ Material 3 Support: Modern
DropdownMenuintegration with fullMenuStylecustomization (CustomDropdown) - ✅ Cupertino Native UI: iOS-native
CupertinoPickermodal sheet with haptic feedback (CupertinoDropdown) - ✅ Full Layout Customization: Use
itemBuilderandselectedBuilderto render any custom widget - ✅ Type-Safe Generic Support: Works seamlessly with any model class or primitive type
- ✅ Form Validation: Built-in support for validation error messages and styling
- ✅ Search & Filter: Built-in search and filtering capabilities
- ✅ Rich Icon Support: Add
prefixIcon,suffixIcon,leadingIcon, ortrailingIcon - ✅ WASM & Multiplatform: 100% compatible with Android, iOS, Web (WASM), macOS, Windows, and Linux
Getting Started
Add gt_dropdown as a dependency in your pubspec.yaml file:
dependencies:
gt_dropdown: ^1.3.0
Then run:
flutter pub get
Usage
1. Adaptive Dropdown (Recommended)
Automatically renders CustomDropdown (Material 3) on Android, Web, and Desktop, and CupertinoDropdown on iOS and macOS.
import 'package:gt_dropdown/gt_dropdown.dart';
AdaptiveDropdown<String>(
items: const ['Apple', 'Banana', 'Orange'],
initialSelection: 'Apple',
itemBuilder: (context, item) => Text(item),
onSelected: (value) => print('Selected: $value'),
label: const Text('Choose Fruit'),
hintText: 'Select a fruit',
)
2. Material 3 CustomDropdown
import 'package:gt_dropdown/gt_dropdown.dart';
CustomDropdown<String>(
items: const ['Light', 'Dark', 'System'],
initialSelection: 'System',
itemBuilder: (context, item) => Text(item),
onSelected: (value) => print('Selected: $value'),
label: const Text('Theme'),
hintText: 'Choose a theme',
prefixIcon: const Icon(Icons.palette, size: 20),
borderRadius: 12,
menuElevation: 4,
)
3. Native Cupertino Dropdown (iOS Style)
import 'package:gt_dropdown/gt_dropdown.dart';
CupertinoDropdown<String>(
items: const ['United States', 'Germany', 'Japan', 'India'],
initialSelection: 'United States',
placeholder: 'Select Country',
label: const Text('Country'),
onSelected: (value) => print('Selected: $value'),
)
4. Model Class with Custom Layout
class Country {
final String name;
final String flag;
Country(this.name, this.flag);
@override
String toString() => name;
}
CustomDropdown<Country>(
items: [
Country('USA', '🇺🇸'),
Country('India', '🇮🇳'),
Country('Japan', '🇯🇵'),
],
itemBuilder: (context, country) => Row(
children: [
Text(country.flag, style: const TextStyle(fontSize: 20)),
const SizedBox(width: 10),
Text(country.name),
],
),
onSelected: (value) => setState(() => selectedCountry = value),
label: const Text('Country'),
hintText: 'Select your country',
prefixIcon: const Icon(Icons.flag, size: 20),
)
5. With Form Validation
CustomDropdown<String>(
items: const ['Option 1', 'Option 2', 'Option 3'],
itemBuilder: (context, item) => Text(item),
onSelected: (value) => setState(() => selected = value),
label: const Text('Required Field'),
hintText: 'Please select an option',
validationMessage: selected == null ? 'This field is required' : null,
)
6. Searchable Dropdown
CustomDropdown<String>(
items: const [
'Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola',
'Argentina', 'Armenia', 'Australia', 'Austria', 'Azerbaijan',
],
itemBuilder: (context, item) => Text(item),
onSelected: (value) => print(value),
enableSearch: true,
label: const Text('Search Country'),
hintText: 'Type to search...',
menuHeight: 300,
prefixIcon: const Icon(Icons.search, size: 20),
)
Widget Properties
CustomDropdown
| Property | Type | Description |
|---|---|---|
items |
List<T>? |
List of items to display |
itemBuilder |
Widget Function(BuildContext, T) |
Builder for each dropdown item |
onSelected |
ValueChanged<T?>? |
Callback when an item is selected |
initialSelection |
T? |
Initially selected value |
enabled |
bool |
Whether the dropdown is enabled |
enableSearch |
bool |
Enable search functionality |
enableFilter |
bool |
Enable filter functionality |
label |
Widget? |
Label widget above the dropdown |
hintText |
String? |
Hint text when nothing is selected |
validationMessage |
String? |
Validation error message |
prefixIcon |
Widget? |
Icon before the selected text |
suffixIcon |
Widget? |
Icon after the selected text |
width |
double? |
Custom width for the dropdown |
menuHeight |
double? |
Maximum height of the dropdown menu |
borderRadius |
double? |
Border radius for the menu |
menuBackgroundColor |
Color? |
Background color of the menu |
menuElevation |
double? |
Elevation of the dropdown menu |
menuStyle |
MenuStyle? |
Complete menu style customization |
CupertinoDropdown
| Property | Type | Description |
|---|---|---|
items |
List<T> |
List of selectable items |
initialSelection |
T? |
Initially selected value |
onSelected |
ValueChanged<T?>? |
Callback when an item is selected |
itemBuilder |
Widget Function(BuildContext, T)? |
Builder for items in picker wheel |
selectedBuilder |
Widget Function(BuildContext, T?)? |
Custom builder for closed button state |
label |
Widget? |
Label widget displayed above field |
placeholder |
String? |
Placeholder text when empty |
validationMessage |
String? |
Error message beneath field |
pickerHeight |
double |
Height of the iOS picker sheet |
doneButtonText |
String |
Toolbar confirm button text |
cancelButtonText |
String |
Toolbar cancel button text |
Migration from GTDropdown (v1.0.x)
The legacy GTDropdown is preserved for backward compatibility. To migrate to modern widgets:
// Old way (deprecated)
GTDropdown<String>(
items: const ['Option 1', 'Option 2'],
defaultText: 'Select an option',
onChanged: (value) => print(value),
)
// New recommended way
CustomDropdown<String>(
items: const ['Option 1', 'Option 2'],
itemBuilder: (context, item) => Text(item),
hintText: 'Select an option',
onSelected: (value) => print(value),
)
Contributing & Issues
Contributions are welcome! If you encounter an issue or have a feature request, please report it on the GitHub Issue Tracker.
License
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Libraries
- custom_dropdown/custom_dropdown
- Overlay-based custom dropdown widget implementation.
- custom_dropdown/custom_dropdown_config
- Configuration classes for custom dropdown appearance and behavior.
- custom_dropdown/custom_dropdown_example
- Example showcase for custom overlay dropdown.
- flutter_own_dropdown/dropdown_example
- Example widgets showcasing CustomDropdown features.
- flutter_own_dropdown/dropdown_example_two
- Showcase examples demonstrating CustomDropdown in application contexts.
- flutter_own_dropdown/master_dropdown
- gt_dropdown
- GT Dropdown Package
- legacy/gt_dropdown_legacy