| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import 'package:flutter/material.dart';
- import 'package:japp_flutter/core/models/dropdown_item.dart';
- class AppDropdown<T> extends StatelessWidget {
- final String label;
- final T? value;
- final List<DropdownItem<T>> items; // 改为接收通用列表
- final ValueChanged<T?> onChanged;
- final FormFieldValidator<T>? validator;
- final String? hintText;
- final bool isExpanded;
- final Widget? prefixIcon;
- final InputBorder? border;
- final TextStyle? textStyle;
- final double? iconSize;
- final Color? iconColor;
- const AppDropdown({
- super.key,
- required this.label,
- required this.value,
- required this.items,
- required this.onChanged,
- this.validator,
- this.hintText,
- this.isExpanded = true,
- this.prefixIcon,
- this.border,
- this.textStyle,
- this.iconSize = 20.0,
- this.iconColor,
- });
- @override
- Widget build(BuildContext context) {
- return DropdownButtonFormField<T>(
- decoration: InputDecoration(
- labelText: label,
- hintText: hintText,
- border: border ?? const OutlineInputBorder(),
- prefixIcon: prefixIcon,
- ),
- value: value,
- items: items.map((item) {
- return DropdownMenuItem<T>(
- value: item.value,
- child: Row(
- children: [
- if (item.icon != null)
- Icon(
- item.icon,
- size: iconSize,
- color: item.iconColor ?? iconColor,
- ),
- if (item.icon != null) const SizedBox(width: 8),
- Text(
- item.label,
- style: textStyle ?? Theme.of(context).textTheme.bodyMedium,
- ),
- ],
- ),
- );
- }).toList(),
- onChanged: onChanged,
- validator: validator,
- isExpanded: isExpanded,
- );
- }
- }
|