app_dropdown_modelo.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:flutter/material.dart';
  2. import '../themes/themes.dart';
  3. class AppDropdownModel<T> extends StatelessWidget {
  4. final String? etiqueta;
  5. final String? hint;
  6. final T? selectedValue;
  7. final void Function(T?)? onChanged;
  8. final List<DropdownMenuItem<T>>? items;
  9. const AppDropdownModel({
  10. super.key,
  11. this.etiqueta,
  12. this.hint,
  13. this.selectedValue,
  14. this.onChanged,
  15. required this.items,
  16. });
  17. double _getFontSize(BuildContext context) {
  18. double screenWidth = MediaQuery.of(context).size.width;
  19. if (screenWidth < 480) {
  20. return 12;
  21. } else if (screenWidth < 800) {
  22. return 15;
  23. }
  24. return 18;
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. double fontSize = _getFontSize(context);
  29. TextStyle dropdownTextStyle =
  30. TextStyle(fontSize: fontSize, color: Colors.black);
  31. return Column(
  32. crossAxisAlignment: CrossAxisAlignment.start,
  33. children: [
  34. if (etiqueta != null && etiqueta!.isNotEmpty)
  35. Text(
  36. etiqueta!,
  37. style: TextStyle(
  38. fontSize: fontSize,
  39. fontWeight: FontWeight.bold,
  40. ),
  41. ),
  42. if (etiqueta != null && etiqueta!.isNotEmpty)
  43. const SizedBox(
  44. height: 5,
  45. ),
  46. Container(
  47. decoration: BoxDecoration(
  48. color: Colors.white, borderRadius: BorderRadius.circular(15)),
  49. child: DropdownButtonFormField(
  50. hint: Text(hint ?? '', style: dropdownTextStyle),
  51. style: dropdownTextStyle,
  52. borderRadius: BorderRadius.circular(10),
  53. icon: Icon(
  54. Icons.arrow_drop_down_circle,
  55. color: AppTheme.primary,
  56. ),
  57. decoration: InputDecoration(
  58. floatingLabelStyle: TextStyle(
  59. color: AppTheme.primary,
  60. fontSize: fontSize,
  61. ),
  62. labelStyle: TextStyle(color: Colors.grey, fontSize: fontSize),
  63. focusedBorder: OutlineInputBorder(
  64. borderRadius: BorderRadius.circular(15),
  65. borderSide: BorderSide(color: AppTheme.tertiary),
  66. ),
  67. enabledBorder: OutlineInputBorder(
  68. borderRadius: BorderRadius.circular(15),
  69. borderSide: const BorderSide(color: Colors.grey),
  70. ),
  71. ),
  72. value: selectedValue,
  73. items: items,
  74. onChanged: onChanged,
  75. ),
  76. ),
  77. ],
  78. );
  79. }
  80. }