import 'package:flutter/material.dart'; import 'package:japp_flutter/core/models/dropdown_item.dart'; class AppDropdown extends StatelessWidget { final String label; final T? value; final List> items; // 改为接收通用列表 final ValueChanged onChanged; final FormFieldValidator? 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( decoration: InputDecoration( labelText: label, hintText: hintText, border: border ?? const OutlineInputBorder(), prefixIcon: prefixIcon, ), value: value, items: items.map((item) { return DropdownMenuItem( 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, ); } }