CustomDropdown<T> class
A styled dropdown widget with consistent theming
This generic widget allows for creating dropdown selectors with a consistent appearance matching other form elements.
Example:
// In a StatefulWidget
String _selectedValue = 'option1';
CustomDropdown<String>(
label: 'Select Option',
value: _selectedValue,
items: [
DropdownMenuItem(value: 'option1', child: Text('Option 1')),
DropdownMenuItem(value: 'option2', child: Text('Option 2')),
DropdownMenuItem(value: 'option3', child: Text('Option 3')),
],
onChanged: (value) {
setState(() {
_selectedValue = value!;
});
},
)
Using with enum values:
enum PaymentMethod { creditCard, paypal, bankTransfer }
// In a StatefulWidget
PaymentMethod _selectedMethod = PaymentMethod.creditCard;
CustomDropdown<PaymentMethod>(
label: 'Payment Method',
value: _selectedMethod,
items: PaymentMethod.values.map((method) {
return DropdownMenuItem(
value: method,
child: Text(method.toString().split('.').last),
);
}).toList(),
onChanged: (value) {
setState(() {
_selectedMethod = value!;
});
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- CustomDropdown
Constructors
-
CustomDropdown({Key? key, required String label, required T value, required List<
DropdownMenuItem< items, required ValueChanged<T> >T?> onChanged}) -
Creates a CustomDropdown with the required parameters
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
items
→ List<
DropdownMenuItem< T> > -
List of available dropdown items
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- label → String
-
The label text displayed for this dropdown
final
-
onChanged
→ ValueChanged<
T?> -
Callback function when selection changes
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
The currently selected value
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited