app_dropdown.dart 2.7 KB

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