app_dropdown_modelo.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 16;
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. double fontSize = _getFontSize(context);
  29. TextStyle dropdownTextStyle = TextStyle(fontSize: fontSize);
  30. return Column(
  31. crossAxisAlignment: CrossAxisAlignment.start,
  32. children: [
  33. Text(
  34. etiqueta.toString(),
  35. style: TextStyle(
  36. fontSize: fontSize,
  37. fontWeight: FontWeight.bold,
  38. ),
  39. ),
  40. const SizedBox(
  41. height: 5,
  42. ),
  43. Container(
  44. decoration: BoxDecoration(
  45. color: Colors.white, borderRadius: BorderRadius.circular(15)),
  46. // width: size.width,
  47. child: DropdownButtonFormField(
  48. hint: Text('$hint', style: dropdownTextStyle),
  49. style: dropdownTextStyle,
  50. borderRadius: BorderRadius.circular(10),
  51. icon: Icon(
  52. Icons.arrow_drop_down_circle,
  53. color: AppTheme.primary,
  54. ),
  55. decoration: InputDecoration(
  56. // labelText: 'Seleccione una salida reciente',
  57. floatingLabelStyle: TextStyle(
  58. color: AppTheme.primary,
  59. fontSize: fontSize,
  60. ),
  61. labelStyle: TextStyle(color: Colors.grey, fontSize: fontSize),
  62. focusedBorder: OutlineInputBorder(
  63. borderRadius: BorderRadius.circular(15),
  64. borderSide: BorderSide(color: AppTheme.primary),
  65. ),
  66. enabledBorder: OutlineInputBorder(
  67. borderRadius: BorderRadius.circular(15),
  68. borderSide: const BorderSide(color: Colors.grey),
  69. ),
  70. ),
  71. value: selectedValue,
  72. items: items,
  73. onChanged: onChanged,
  74. ),
  75. ),
  76. ],
  77. );
  78. }
  79. }