123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // ignore_for_file: must_be_immutable
- import 'package:flutter/material.dart';
- import '../themes/themes.dart';
- class AppDropdown extends StatelessWidget {
- final double? height;
- final double? width;
- final String? labelText;
- final String? helperText;
- final String? selectedValue;
- final List listaOpciones;
- final String? hint;
- final void Function(Object?)? onChanged;
- String? etiqueta;
- AppDropdown({
- super.key,
- this.labelText,
- this.onChanged,
- this.width,
- this.height,
- this.hint,
- this.helperText,
- this.etiqueta,
- required this.selectedValue,
- required this.listaOpciones,
- });
- double _getFontSize(BuildContext context) {
- double screenWidth = MediaQuery.of(context).size.width;
- if (screenWidth < 480) {
- return 12;
- } else if (screenWidth < 800) {
- return 15;
- }
- return 16;
- }
- @override
- Widget build(BuildContext context) {
- double fontSize = _getFontSize(context);
- TextStyle dropdownTextStyle = TextStyle(fontSize: fontSize);
- etiqueta ??= "";
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- etiqueta.toString(),
- style: TextStyle(
- fontSize: fontSize,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(
- height: 5,
- ),
- DropdownButtonFormField(
- hint: hint != null ? Text('$hint') : null,
- borderRadius: BorderRadius.circular(15),
- dropdownColor: Colors.white,
- icon: Icon(
- Icons.arrow_drop_down_circle,
- color: AppTheme.primary,
- ),
- decoration: InputDecoration(
- labelText: labelText,
- helperText: helperText,
- floatingLabelStyle: TextStyle(
- color: AppTheme.primary,
- fontSize: fontSize,
- ),
- labelStyle: TextStyle(color: Colors.grey, fontSize: fontSize),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(15),
- borderSide: BorderSide(color: AppTheme.tertiary),
- ),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(15),
- borderSide: const BorderSide(color: Colors.grey),
- ),
- ),
- value: selectedValue,
- items: listaOpciones
- .map(
- (e) => DropdownMenuItem(
- value: e,
- child: Text(
- e.toString().toUpperCase(),
- style: TextStyle(fontSize: fontSize),
- ),
- ),
- )
- .toList(),
- onChanged: onChanged,
- ),
- ],
- );
- }
- }
|