import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:memorias_calculo/src/front/widgets/formatters.dart';

class CalculadoraAmbientalPage extends StatefulWidget {
  final bool errorConexion;

  const CalculadoraAmbientalPage({Key? key, required this.errorConexion}) : super(key: key);

  @override
  _CalculadoraAmbientalPageState createState() => _CalculadoraAmbientalPageState();
}

class _CalculadoraAmbientalPageState extends State<CalculadoraAmbientalPage> {
  final TextEditingController _volumenController = TextEditingController();
  final TextEditingController _renovaController = TextEditingController();
  final TextEditingController _acce4Controller = TextEditingController();
  final TextEditingController _cantEqController = TextEditingController();
  double _valVolumen = 0.0;
  double _valCaudal = 0.0;
  double _valAcce1 = 0.0;
  double _valAcce2 = 0.0;
  double _valAcce3 = 0.0;
  double _valAcce4 = 0.0;
  double _valPerdAdi = 0.0;
  int _valCaudalCFM = 0;
  int _valCantEq = 0;
  int _valRenova = 0;
  int _valLonLouv = 0;
  int _valAltLouv = 0;
  String _unidadVolumen = "m³";
  String _unidadCaudal = "m³/h";
  String _acce1 = "Sin Accesorio";
  String _acce2 = "Sin Accesorio";
  String _acce3 = "Sin Accesorio";
  String _funcion = "";
  String _montaje = "";
  String _material = "";
  bool _perdidasAdicionales = false;

  late String _velLouvers;

  static const List<String> _unidadesVolumen = ["m³", "ft³"];
  static const List<String> _unidadesCaudal = ["m³/h", "CFM"];
  static const List<String> _funciones = ["Inyección", "Extracción"];
  static const List<String> _montajes = ["Pared", "Tejado", "Conducto"];
  static const List<String> _materiales = ["Aluminio", "Lámina Galvanizada"];
  static const Map<String, double> _accesorios = {
    "Sin Accesorio" : 0.0,
    "Persiana de Sobrepresión" : 0.07,
    "Cubierta Intemperie 45°" : 0.01,
    "Malla de Protección" : 0.02
  };
  static const Map<int, Map<int, double>> _louvers ={
    12 : { 12: 0.266, 24: 0.630, 36:  0.995, 48:  1.360, 60:  1.680, 72:  2.040, 84:  2.410, 96:  2.770, 108:  3.090, 120:  3.460 },
    24 : { 12: 0.642, 24: 1.520, 36:  2.400, 48:  3.280, 60:  4.050, 72:  4.930, 84:  5.810, 96:  6.690, 108:  7.460, 120:  8.340 },
    36 : { 12: 1.080, 24: 2.560, 36:  4.040, 48:  5.520, 60:  6.810, 72:  8.290, 84:  9.770, 96: 11.250, 108: 12.540, 120: 14.020 },
    48 : { 12: 1.460, 24: 3.460, 36:  5.460, 48:  7.460, 60:  9.210, 72: 11.210, 84: 13.210, 96: 15.210, 108: 16.960, 120: 18.960 },
    60 : { 12: 1.910, 24: 4.530, 36:  7.150, 48:  9.770, 60: 12.060, 72: 14.680, 84: 17.300, 96: 19.920, 108: 22.210, 120: 24.830 },
    72 : { 12: 2.360, 24: 5.600, 36:  8.840, 48: 12.080, 60: 14.920, 72: 18.160, 84: 21.390, 96: 24.630, 108: 27.470, 120: 30.710 },
    84 : { 12: 2.740, 24: 6.490, 36: 10.250, 48: 14.000, 60: 17.290, 72: 21.050, 84: 24.800, 96: 28.560, 108: 31.840, 120: 35.600 },
    96 : { 12: 3.170, 24: 7.530, 36: 11.880, 48: 16.240, 60: 20.050, 72: 24.400, 84: 28.760, 96: 33.110, 108: 36.920, 120: 41.270 },
    108: { 12: 3.550, 24: 8.430, 36: 13.300, 48: 18.180, 60: 22.450, 72: 27.320, 84: 32.200, 96: 37.070, 108: 41.340, 120: 46.210 },
    120: { 12: 4.010, 24: 9.500, 36: 15.000, 48: 20.490, 60: 25.300, 72: 30.790, 84: 36.290, 96: 41.780, 108: 46.590, 120: 52.090 },
  };
  static const Map<String, double> _louversVal = {
    "Sin Louvers" : 0.0,
    "500" : 0.04,
    "600" : 0.06,
    "700" : 0.09,
    "800" : 0.10,
    "900" : 0.13,
    "1000" : 0.16,
    "1068" : 0.18,
  };

  final List<int> _listaLonLouvers = [];

  @override
  void initState() {
    super.initState();

    _volumenController.text = _valVolumen.toStringAsFixed(2);
    _renovaController.text = _valRenova.toString();
    _acce4Controller.text = _valAcce4.toStringAsFixed(2);
    _cantEqController.text = _valCantEq.toString();

    _velLouvers = _louversVal.keys.first;

    for(int i = 0; i < 11; i++){
      int val = i * 12;
      _listaLonLouvers.add(val);
    }
    _valLonLouv = _listaLonLouvers.first;
    _valAltLouv = _listaLonLouvers.first;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LayoutBuilder(
        builder: (context, constraints){
          final parentWidth = constraints.maxWidth;

          double containerWidth = parentWidth > 1440
              ? parentWidth*0.5 : parentWidth > 1280 && parentWidth <= 1440
              ? parentWidth*0.6 : parentWidth > 1080 && parentWidth <= 1280
              ? parentWidth*0.75 : parentWidth > 900 && parentWidth <= 1080
              ? parentWidth*0.8 : parentWidth > 720 && parentWidth <= 900
              ? parentWidth*0.85 : parentWidth > 540 && parentWidth <= 720
              ? parentWidth*0.9 : parentWidth;
          double containerMargin = (parentWidth - containerWidth) / 2;

          return SingleChildScrollView(
            child: Container(
              width: containerWidth,
              margin: EdgeInsets.symmetric(
                horizontal: containerMargin,
              ),
              child: Column(
                children: [
                  const SizedBox(height: 8.0),
                  Container(
                    margin: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Row(
                      children: [
                        TextButton(
                          child: Text(
                            "Memoria de cálculo de ventilación ambiental >",
                            style: GoogleFonts.roboto(
                              fontSize: 16.0,
                              fontWeight: FontWeight.bold,
                              fontStyle: FontStyle.italic,
                            ),
                          ),
                          onPressed: widget.errorConexion ? () => Navigator.pop(context) : () async{
                            final accion = await showDialog(
                              context: context,
                              barrierDismissible: false,
                              builder: (context) => AlertDialog(
                                title: Text(
                                  "Salir sin guardar",
                                  textAlign: TextAlign.center,
                                  style: GoogleFonts.roboto(
                                    fontWeight: FontWeight.bold,
                                    fontSize: 20.0,
                                    color: Colors.black87,
                                  ),
                                ),
                                content: Text(
                                  "¿Está seguro de salir sin guardar los cambios?",
                                  textAlign: TextAlign.center,
                                  style: GoogleFonts.roboto(
                                    fontSize: 16.0,
                                  ),
                                ),
                                actions: [
                                  TextButton(
                                    child: const Text(
                                      "Salir sin guardar",
                                    ),
                                    onPressed: () => Navigator.pop(context, "salir"),
                                  ),
                                  TextButton(
                                    child: const Text(
                                      "Guardar y salir",
                                    ),
                                    onPressed: () => Navigator.pop(context, "guardar"),
                                  ),
                                  TextButton(
                                    child: const Text(
                                      "Cancelar",
                                    ),
                                    onPressed: () => Navigator.pop(context, "cancelar"),
                                  )
                                ],
                              ),
                            );

                            if(accion == "salir"){
                              Navigator.pop(context);
                            }else if(accion == "guardar"){
                              /*Map<String, Map<String, String>> datos = {
                                "datos": {
                                  "tipoInstalacion" : _tipoInstalacion,
                                  "tipoCampana" : "Campana $_aplicacionCampana $_montajeCampana",
                                  "eqCocina" : _eqCocinaCampana,
                                  "longitud" : "$_valLongitud $_unidadLongitudes",
                                  "ancho" : "$_valAncho $_unidadLongitudes",
                                  "distCapt" : "$_valDistCap $_unidadLongitudes",
                                  "caudalEx" : "${(_caudalExtraccion * _factores[_eqCocinaCampana]!).round()} $_unidadCaudal",
                                  "cauInySug" : "${((_caudalExtraccion * _factores[_eqCocinaCampana]!) * 0.85).round()} $_unidadCaudal",
                                  "velAire" : _tipoInstalacion == "N" ? "$_velocidadAire" : "${_velRec.first}",
                                  "ductoCuadradoCM" : _tipoInstalacion == "N" ? "$_ductoCuadradoCM cm" : _tipoDuctoInstalado == "cuadrado" ? "${_medidaDuctoController.text} cm" : "0 cm",
                                  "ductoCuadradoIN" : _tipoInstalacion == "N" ? "$_ductoCuadradoIN in" : _tipoDuctoInstalado == "cuadrado" ? "${_medidaDuctoController.text} in" : "0 in",
                                  "ductoCircularCM" : _tipoInstalacion == "N" ? "$_ductoCircularCM cm" : _tipoDuctoInstalado == "circular" ? "${_medidaDuctoController.text} cm" : "0 cm",
                                  "ductoCircularIN" : _tipoInstalacion == "N" ? "$_ductoCircularIN in" : _tipoDuctoInstalado == "circular" ? "${_medidaDuctoController.text} in" : "0 in",
                                  "ductoSeleccion" : _tipoInstalacion == "N" ? "$_tipoDucto" : "$_tipoDuctoInstalado",
                                  "unidadesInstalado" : _unidadDucto
                                },
                                if(_confCuad.isNotEmpty)
                                  "campana": _confCuad,
                                if(_cuadricula.isNotEmpty)
                                  "cuadricula": _cuadricula,
                                if(_jsonCalculos.isNotEmpty)
                                  "calculos": { "resultados": _jsonCalculos }
                              };
                              String datosStr = jsonEncode(datos);

                              final guardado = await _cambiarDatos(datosStr);
                              if(guardado){
                                Fluttertoast.showToast(
                                    msg: "El proyecto se guardó satisfactoriamente",
                                    toastLength: Toast.LENGTH_SHORT,
                                    timeInSecForIosWeb: 4,
                                    gravity: ToastGravity.CENTER,
                                    webBgColor: "linear-gradient(to right, #266B1F, #98F58F)"
                                );
                              }else{
                                Fluttertoast.showToast(
                                    msg: "Hubo un error al intentar guardar el proyecto, intentelo de nuevo más tarde.",
                                    toastLength: Toast.LENGTH_SHORT,
                                    timeInSecForIosWeb: 4,
                                    gravity: ToastGravity.CENTER,
                                    webBgColor: "linear-gradient(to right, #b40404, #ff0000)"
                                );
                              }

                              Navigator.pop(context);*/
                            }
                          },
                          style: TextButton.styleFrom(
                            padding: const EdgeInsets.fromLTRB(0.0, 0.0, 8.0, 0.0),
                            minimumSize: const Size(0.0, 0.0),
                            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        Expanded(
                          child: Container(
                            padding: const EdgeInsets.fromLTRB(0.0, 0.0, 8.0, 0.0),
                            child: Text(
                              "Cálculo de equipos de extracción y louvers",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: GoogleFonts.roboto(
                                fontSize: 16.0,
                                color: Colors.black54,
                                fontWeight: FontWeight.bold,
                                fontStyle: FontStyle.italic,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 8.0,
                  ),
                  Row(
                    children: [
                      const SizedBox(width: 32.0),
                      Image.asset(
                        "logo.png",
                        width: 64.0,
                      ),
                      Expanded(
                        child: Container(
                          padding: const EdgeInsets.fromLTRB(208.0, 0.0, 16.0, 0.0),
                          child: Text(
                            "S&P MX  ${"MX".replaceAllMapped(RegExp(r'[A-Z]'), (match) => String.fromCharCode(match.group(0)!.codeUnitAt(0) + 127397))}",
                            textAlign: TextAlign.center,
                            style: const TextStyle(
                              fontFamily: "Helvetica Neue Black Cond",
                              fontSize: 20.0,
                            ),
                          ),
                        ),
                      ),
                      Image.asset(
                        "logo_completo.png",
                        width: 256.0,
                      ),
                      const SizedBox(width: 32.0),
                    ],
                  ),
                  const SizedBox(
                    height: 32.0,
                  ),
                  Image.asset(
                    "1.png",
                    width: 120.0,
                  ),
                  const SizedBox(
                    height: 48.0,
                  ),
                  Container(
                    width: double.infinity,
                    padding: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Text(
                      "Cálculo de equipos de extracción y louvers".toUpperCase(),
                      textAlign: TextAlign.center,
                      style: const TextStyle(
                        fontFamily: "Helvetica Neue Black Cond",
                        fontSize: 28.0,
                      ),
                    ),
                  ),
                  const SizedBox(
                    height: 8.0,
                  ),
                  Container(
                    padding: const EdgeInsets.symmetric(horizontal: 32.0),
                    width: double.infinity,
                    child: const Text(
                      "Por favor ingresa los datos requeridos para el cálculo de los equipos.",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        fontFamily: "Helvetica Neue Light",
                        fontSize: 22.0,
                        fontWeight: FontWeight.w600,
                        color: Color.fromRGBO(104, 104, 104, 1),
                      ),
                    ),
                  ),
                  const SizedBox(
                    height: 32.0,
                  ),
                  Container(
                    margin: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Row(
                      children: [
                        Text(
                          "Volumen:",
                          style: GoogleFonts.roboto(
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0,
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        Expanded(
                          child: SizedBox(
                            height: 64.0,
                            width: double.infinity,
                            child: Stack(
                              alignment: Alignment.center,
                              children: [
                                TextField(
                                  textAlign: TextAlign.center,
                                  controller: _volumenController,
                                  maxLength: 10,
                                  decoration: const InputDecoration(
                                    counterText: "",
                                    counterStyle: TextStyle(
                                      height: double.minPositive,
                                    ),
                                  ),
                                  inputFormatters: [
                                    DecimalTextInputFormatter()
                                  ],
                                  onChanged: (val){
                                    _valVolumen = double.parse(val);
                                    _calcularCantidadAire();
                                  },
                                ),
                                Positioned(
                                  left: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.remove,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valVolumen = _valVolumen - 0.1;

                                      if(_valVolumen < 0){
                                        _valVolumen = 0.0;
                                      }

                                      _volumenController.text = _valVolumen.toStringAsFixed(2);
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                                Positioned(
                                  right: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.add,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valVolumen = _valVolumen + 0.1;

                                      if(_valVolumen > 999){
                                        _valVolumen = 999.0;
                                      }

                                      _volumenController.text = _valVolumen.toStringAsFixed(2);
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        DropdownButton<String>(
                          value: _unidadVolumen,
                          onChanged: (value) => setState((){
                            _unidadVolumen = value!;
                            _calcularCantidadAire();
                          }),
                          items: _unidadesVolumen.map((e) => DropdownMenuItem<String>(
                            child: Text(
                              e,
                              style: GoogleFonts.roboto(
                                fontSize: 18.0,
                              ),
                            ),
                            value: e,
                          )).toList(),
                        ),
                        const SizedBox(width: 8.0),
                        IconButton(
                          icon: const Icon(
                            Icons.info_outline,
                          ),
                          onPressed: () => showDialog(
                            context: context,
                            barrierDismissible: true,
                            builder: (context) => const AlertDialog(
                              title: Text(
                                "Volumen",
                              ),
                              content: Text(
                                "Volumen del lugar a ventilar",
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 16.0,
                  ),
                  Container(
                    margin: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Row(
                      children: [
                        Text(
                          "# Cambios de Aire:",
                          style: GoogleFonts.roboto(
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0,
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        Expanded(
                          child: SizedBox(
                            height: 64.0,
                            width: double.infinity,
                            child: Stack(
                              alignment: Alignment.center,
                              children: [
                                TextField(
                                  textAlign: TextAlign.center,
                                  controller: _renovaController,
                                  maxLength: 3,
                                  decoration: const InputDecoration(
                                    counterText: "",
                                    counterStyle: TextStyle(
                                      height: double.minPositive,
                                    ),
                                  ),
                                  inputFormatters: [
                                    IntegerTextInputFormatter()
                                  ],
                                  onChanged: (val){
                                    try{
                                      _valRenova = int.parse(val);
                                    }catch(e){
                                      _valRenova = 0;
                                    }
                                    _calcularCantidadAire();
                                  },
                                ),
                                Positioned(
                                  left: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.remove,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valRenova = _valRenova - 1;

                                      if(_valRenova < 0){
                                        _valRenova = 0;
                                      }

                                      _renovaController.text = _valRenova.toString();
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                                Positioned(
                                  right: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.add,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valRenova = _valRenova + 1;

                                      if(_valRenova > 999){
                                        _valRenova = 999;
                                      }

                                      _renovaController.text = _valRenova.toString();
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        Container(
                          child: Text(
                            "Por hora",
                            style: GoogleFonts.roboto(
                              fontSize: 18.0,
                            ),
                          ),
                          padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                          decoration: BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                color: Colors.black.withOpacity(0.18),
                                width: 2.0,
                              ),
                            ),
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        IconButton(
                          icon: const Icon(
                            Icons.info_outline,
                          ),
                          onPressed: () => showDialog(
                            context: context,
                            barrierDismissible: true,
                            builder: (context) => const AlertDialog(
                              title: Text(
                                "# Cambios de Aire",
                              ),
                              content: Text(
                                "Son las veces que se renovará el aire por hora",
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 16.0,
                  ),
                  Container(
                    margin: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Row(
                      children: [
                        Text(
                          "Cantidad de Equipos Requeridos:",
                          style: GoogleFonts.roboto(
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0,
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        Expanded(
                          child: SizedBox(
                            height: 64.0,
                            width: double.infinity,
                            child: Stack(
                              alignment: Alignment.center,
                              children: [
                                TextField(
                                  textAlign: TextAlign.center,
                                  controller: _cantEqController,
                                  maxLength: 3,
                                  decoration: const InputDecoration(
                                    counterText: "",
                                    counterStyle: TextStyle(
                                      height: double.minPositive,
                                    ),
                                  ),
                                  inputFormatters: [
                                    IntegerTextInputFormatter()
                                  ],
                                  onChanged: (val) => setState(() {
                                    try{
                                      _valCantEq = int.parse(val);
                                    }catch(e){
                                      _valCantEq = 0;
                                    }
                                    _calcularCantidadAire();
                                  }),
                                ),
                                Positioned(
                                  left: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.remove,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valCantEq = _valCantEq - 1;

                                      if(_valCantEq < 0){
                                        _valCantEq = 0;
                                      }

                                      _cantEqController.text = _valCantEq.toString();
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                                Positioned(
                                  right: 0.0,
                                  child: IconButton(
                                    icon: const Icon(
                                      Icons.add,
                                      color: Colors.black45,
                                    ),
                                    onPressed: () => setState(() {
                                      _valCantEq = _valCantEq + 1;

                                      if(_valCantEq > 999){
                                        _valCantEq = 999;
                                      }

                                      _cantEqController.text = _valCantEq.toString();
                                      _calcularCantidadAire();
                                    }),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                        const SizedBox(width: 8.0),
                        IconButton(
                          icon: const Icon(
                            Icons.info_outline,
                          ),
                          onPressed: () => showDialog(
                            context: context,
                            barrierDismissible: true,
                            builder: (context) => const AlertDialog(
                              title: Text(
                                "# Cambios de Aire",
                              ),
                              content: Text(
                                "Son las veces que se renovará el aire por hora",
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  AnimatedCrossFade(
                    firstChild: Container(),
                    secondChild: Column(
                      children: [
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            children: [
                              Text(
                                "Cantidad Total de Aire Requerido:",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: GoogleFonts.roboto(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18.0,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Expanded(
                                child: Row(
                                  children: [
                                    Text(
                                      _valCaudal.toStringAsFixed(4),
                                      style: GoogleFonts.roboto(
                                        fontSize: 18.0,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _unidadCaudal,
                                        onChanged: (value) => setState((){
                                          _unidadCaudal = value!;
                                          _calcularCantidadAire();
                                        }),
                                        isExpanded: true,
                                        items: _unidadesCaudal.map((e) => DropdownMenuItem<String>(
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                          value: e,
                                        )).toList(),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "Pérdidas Adicionales:",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: GoogleFonts.roboto(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18.0,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Switch(
                                value: _perdidasAdicionales,
                                onChanged: (val) => setState(() => _perdidasAdicionales = val),
                                activeTrackColor: const Color.fromRGBO(180, 4, 4, 0.75),
                                activeColor: const Color.fromRGBO(180, 4, 4, 1),
                              )
                            ],
                          ),
                        ),
                        AnimatedCrossFade(
                          firstChild: Container(),
                          secondChild: Column(
                            children: [
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Text(
                                      "Accesorio 1:",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: GoogleFonts.roboto(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 18.0,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _acce1,
                                        onChanged: (val) => setState(() {
                                          _acce1 = val!;
                                          _valAcce1 = _accesorios[val]!;
                                          _calcularPerdidasAdicionales();
                                        }),
                                        items: _accesorios.keys.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "${_valAcce1.toStringAsFixed(2)} in c.d.a",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Text(
                                      "Accesorio 2:",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: GoogleFonts.roboto(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 18.0,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _acce2,
                                        onChanged: (val) => setState(() {
                                          _acce2 = val!;
                                          _valAcce2 = _accesorios[val]!;
                                          _calcularPerdidasAdicionales();
                                        }),
                                        items: _accesorios.keys.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "${_valAcce2.toStringAsFixed(2)} in c.d.a",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Text(
                                      "Accesorio 3:",
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      style: GoogleFonts.roboto(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 18.0,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _acce3,
                                        onChanged: (val) => setState(() {
                                          _acce3 = val!;
                                          _valAcce3 = _accesorios[val]!;
                                          _calcularPerdidasAdicionales();
                                        }),
                                        items: _accesorios.keys.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "${_valAcce3.toStringAsFixed(2)} in c.d.a",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    RichText(
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      text: TextSpan(
                                        children: [
                                          TextSpan(
                                            text: "Accesorio 4:",
                                            style: GoogleFonts.roboto(
                                              fontWeight: FontWeight.bold,
                                              fontSize: 18.0,
                                            ),
                                          ),
                                          const TextSpan(
                                            text: " Perdidas Adicionales"
                                          )
                                        ],
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: SizedBox(
                                        height: 64.0,
                                        width: double.infinity,
                                        child: Stack(
                                          alignment: Alignment.center,
                                          children: [
                                            TextField(
                                              textAlign: TextAlign.center,
                                              controller: _acce4Controller,
                                              maxLength: 10,
                                              decoration: const InputDecoration(
                                                counterText: "",
                                                counterStyle: TextStyle(
                                                  height: double.minPositive,
                                                ),
                                              ),
                                              inputFormatters: [
                                                DecimalTextInputFormatter()
                                              ],
                                              onChanged: (val){
                                                _valAcce4 = double.parse(val);
                                                _calcularPerdidasAdicionales();
                                              },
                                            ),
                                            Positioned(
                                              left: 0.0,
                                              child: IconButton(
                                                icon: const Icon(
                                                  Icons.remove,
                                                  color: Colors.black45,
                                                ),
                                                onPressed: () => setState(() {
                                                  _valAcce4 = _valAcce4 - 0.1;

                                                  if(_valAcce4 < 0){
                                                    _valVolumen = 0.0;
                                                  }

                                                  _acce4Controller.text = _valAcce4.toStringAsFixed(2);
                                                  _calcularPerdidasAdicionales();
                                                }),
                                              ),
                                            ),
                                            Positioned(
                                              right: 0.0,
                                              child: IconButton(
                                                icon: const Icon(
                                                  Icons.add,
                                                  color: Colors.black45,
                                                ),
                                                onPressed: () => setState(() {
                                                  _valAcce4 = _valAcce4 + 0.1;

                                                  if(_valAcce4 > 999){
                                                    _valAcce4 = 999.0;
                                                  }

                                                  _acce4Controller.text = _valAcce4.toStringAsFixed(2);
                                                  _calcularPerdidasAdicionales();
                                                }),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "in c.d.a",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              AnimatedCrossFade(
                                firstChild: Container(),
                                secondChild: Column(
                                  children: [
                                    const SizedBox(
                                      height: 16.0,
                                    ),
                                    Container(
                                      margin: const EdgeInsets.symmetric(
                                        horizontal: 32.0,
                                      ),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: [
                                          Text(
                                            "Presión Estática Externa:",
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: GoogleFonts.roboto(
                                              fontWeight: FontWeight.bold,
                                              fontSize: 18.0,
                                            ),
                                          ),
                                          const SizedBox(width: 8.0),
                                          Container(
                                            child: Text(
                                              "$_valPerdAdi in c.d.a",
                                              style: GoogleFonts.roboto(
                                                fontSize: 18.0,
                                              ),
                                            ),
                                            padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                            decoration: BoxDecoration(
                                              border: Border(
                                                bottom: BorderSide(
                                                  color: Colors.black.withOpacity(0.18),
                                                  width: 2.0,
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                                duration: const Duration(
                                  milliseconds: 250,
                                ),
                                crossFadeState: _valPerdAdi == 0 ? CrossFadeState.showFirst : CrossFadeState.showSecond,
                              ),
                            ],
                          ),
                          duration: const Duration(
                            milliseconds: 250,
                          ),
                          crossFadeState: _perdidasAdicionales ? CrossFadeState.showSecond : CrossFadeState.showFirst,
                        ),
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            children: [
                              Text(
                                "Velocidad de Paso en Louvers:",
                                style: GoogleFonts.roboto(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18.0,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Expanded(
                                child: DropdownButton<String>(
                                  value: _velLouvers,
                                  onChanged: (val) => setState(() {
                                    _velLouvers = val!;
                                  }),
                                  items: _louversVal.keys.map((e) => DropdownMenuItem<String>(
                                    value: e,
                                    child: Text(
                                      e,
                                      style: GoogleFonts.roboto(
                                        fontSize: 18.0,
                                      ),
                                    ),
                                  )).toList(),
                                  isExpanded: true,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Container(
                                child: Text(
                                  "ft/min",
                                  style: GoogleFonts.roboto(
                                    fontSize: 18.0,
                                  ),
                                ),
                                padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                decoration: BoxDecoration(
                                  border: Border(
                                    bottom: BorderSide(
                                      color: Colors.black.withOpacity(0.18),
                                      width: 2.0,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            children: [
                              Text(
                                "Longitud del Louver:",
                                style: GoogleFonts.roboto(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18.0,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Expanded(
                                child: DropdownButton<int>(
                                  value: _valLonLouv,
                                  onChanged: (val) => setState(() {
                                    _valLonLouv = val!;
                                  }),
                                  items: _listaLonLouvers.map((e) => DropdownMenuItem<int>(
                                    value: e,
                                    child: Text(
                                      "$e",
                                      style: GoogleFonts.roboto(
                                        fontSize: 18.0,
                                      ),
                                    ),
                                  )).toList(),
                                  isExpanded: true,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Container(
                                child: Text(
                                  "in",
                                  style: GoogleFonts.roboto(
                                    fontSize: 18.0,
                                  ),
                                ),
                                padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                decoration: BoxDecoration(
                                  border: Border(
                                    bottom: BorderSide(
                                      color: Colors.black.withOpacity(0.18),
                                      width: 2.0,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            children: [
                              Text(
                                "Altura del Louver:",
                                style: GoogleFonts.roboto(
                                  fontWeight: FontWeight.bold,
                                  fontSize: 18.0,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Expanded(
                                child: DropdownButton<int>(
                                  value: _valAltLouv,
                                  onChanged: (val) => setState(() {
                                    _valAltLouv = val!;
                                  }),
                                  items: _listaLonLouvers.map((e) => DropdownMenuItem<int>(
                                    value: e,
                                    child: Text(
                                      "$e",
                                      style: GoogleFonts.roboto(
                                        fontSize: 18.0,
                                      ),
                                    ),
                                  )).toList(),
                                  isExpanded: true,
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Container(
                                child: Text(
                                  "in",
                                  style: GoogleFonts.roboto(
                                    fontSize: 18.0,
                                  ),
                                ),
                                padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                decoration: BoxDecoration(
                                  border: Border(
                                    bottom: BorderSide(
                                      color: Colors.black.withOpacity(0.18),
                                      width: 2.0,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 16.0,
                        ),
                        Container(
                          margin: const EdgeInsets.symmetric(
                            horizontal: 32.0,
                          ),
                          child: Row(
                            children: [
                              Expanded(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(
                                      "Área de Paso Libre:",
                                      style: GoogleFonts.roboto(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 18.0,
                                      ),
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      textAlign: TextAlign.right,
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "${_valLonLouv == 0 || _valAltLouv == 0 ? '0' : _louvers[_valAltLouv]![_valLonLouv]} ft²",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(width: 8.0),
                              Expanded(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Text(
                                      "Presión Estática:",
                                      style: GoogleFonts.roboto(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 18.0,
                                      ),
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                      textAlign: TextAlign.right,
                                    ),
                                    const SizedBox(width: 8.0),
                                    Container(
                                      child: Text(
                                        "${_louversVal[_velLouvers]} in c.d.a",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                      ),
                                      padding: const EdgeInsets.fromLTRB(0, 0, 24.0, 8.0),
                                      decoration: BoxDecoration(
                                        border: Border(
                                          bottom: BorderSide(
                                            color: Colors.black.withOpacity(0.18),
                                            width: 2.0,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                        AnimatedCrossFade(
                          firstChild: Container(),
                          secondChild: Column(
                            children: [
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                padding: const EdgeInsets.all(8.0),
                                color: Colors.black12,
                                width: double.infinity,
                                child: Text(
                                  "Especificación de Equipos de Ventilación",
                                  textAlign: TextAlign.center,
                                  style: GoogleFonts.roboto(
                                    fontSize: 18.0,
                                  ),
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "Cantidad",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Función",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Montaje",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Q (CFM)",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Pe (in c.d.a)",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        _cantEqController.text,
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _funcion.isEmpty ? null : _funcion,
                                        onChanged: (val) => setState(() => _funcion = val!),
                                        items: _funciones.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                        hint: Text(
                                          "Requerido.",
                                          style: GoogleFonts.roboto(
                                            fontSize: 18.0,
                                            color: Colors.black54,
                                            fontStyle: FontStyle.italic
                                          ),
                                        ),
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _montaje.isEmpty ? null : _montaje,
                                        onChanged: (val) => setState(() => _montaje = val!),
                                        items: _montajes.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                        hint: Text(
                                          "Requerido.",
                                          style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                              color: Colors.black54,
                                              fontStyle: FontStyle.italic
                                          ),
                                        ),
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "$_valCaudalCFM",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        (_valPerdAdi + _louversVal[_velLouvers]!).toStringAsFixed(2),
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                padding: const EdgeInsets.all(8.0),
                                color: Colors.black12,
                                width: double.infinity,
                                child: Text(
                                  "Especificación de Louvers",
                                  textAlign: TextAlign.center,
                                  style: GoogleFonts.roboto(
                                    fontSize: 18.0,
                                  ),
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "Cantidad",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Longitud",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Altura",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "Material",
                                        style: GoogleFonts.roboto(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              const SizedBox(
                                height: 16.0,
                              ),
                              Container(
                                margin: const EdgeInsets.symmetric(
                                  horizontal: 32.0,
                                ),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        _velLouvers == "Sin Louvers" || _valAltLouv == 0 || _valLonLouv == 0 ? "0"
                                            : "${(((_valCaudalCFM * _valCantEq) / int.parse(_velLouvers)) / _louvers[_valAltLouv]![_valLonLouv]!).round()}",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "$_valLonLouv",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: Text(
                                        "$_valAltLouv",
                                        style: GoogleFonts.roboto(
                                          fontSize: 18.0,
                                        ),
                                        maxLines: 1,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                      ),
                                    ),
                                    const SizedBox(width: 8.0),
                                    Expanded(
                                      child: DropdownButton<String>(
                                        value: _material.isEmpty ? null : _material,
                                        onChanged: (val) => setState(() => _material = val!),
                                        items: _materiales.map((e) => DropdownMenuItem<String>(
                                          value: e,
                                          child: Text(
                                            e,
                                            style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                            ),
                                          ),
                                        )).toList(),
                                        isExpanded: true,
                                        hint: Text(
                                          "Requerido.",
                                          style: GoogleFonts.roboto(
                                              fontSize: 18.0,
                                              color: Colors.black54,
                                              fontStyle: FontStyle.italic
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                          duration: const Duration(
                            milliseconds: 250,
                          ),
                          crossFadeState: _velLouvers != "Sin Louvers" && _valLonLouv != 0 && _valAltLouv != 0 && _valCantEq != 0 ? CrossFadeState.showSecond : CrossFadeState.showFirst,
                        )
                      ],
                    ),
                    duration: const Duration(
                      milliseconds: 250,
                    ),
                    crossFadeState: _valCaudal == 0 ? CrossFadeState.showFirst : CrossFadeState.showSecond,
                  ),
                  const SizedBox(
                    height: 32.0,
                  ),
                  Container(
                    margin: const EdgeInsets.symmetric(
                      horizontal: 32.0,
                    ),
                    child: Row(
                      children: [
                        Expanded(
                          child: MaterialButton(
                            elevation: 4,
                            padding: const EdgeInsets.symmetric(vertical: 16.0),
                            minWidth: (containerWidth/2)-32,
                            color: const Color(0xFFFF0000),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Image.asset(
                                  "guardar.png",
                                  width: 32.0,
                                ),
                                const SizedBox(width: 8.0),
                                const Text(
                                  "Guardar y regresar",
                                  style: TextStyle(
                                    fontFamily: "Helvetica Neue Black Cond",
                                    color: Colors.white,
                                    fontSize: 28.0,
                                  ),
                                )
                              ],
                            ),
                            onPressed: () async{
                            },
                          ),
                        ),
                        const SizedBox(width: 16.0),
                        Expanded(
                          child: MaterialButton(
                            elevation: 4,
                            padding: const EdgeInsets.symmetric(vertical: 16.0),
                            minWidth: (containerWidth/2)-32,
                            color: const Color(0xFFFF0000),
                            disabledColor: Colors.grey,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Image.asset(
                                  "continuar.png",
                                  width: 32.0,
                                ),
                                const SizedBox(width: 8.0),
                                const Text(
                                  "Continuar",
                                  style: TextStyle(
                                    fontFamily: "Helvetica Neue Black Cond",
                                    color: Colors.white,
                                    fontSize: 28.0,
                                  ),
                                )
                              ],
                            ),
                            onPressed: () => true,
                          ),
                        )
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 32.0,
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }

  void _calcularCantidadAire() => setState(() {
    if(_valVolumen != 0.0 && _valRenova != 0 && _valCantEq != 0){
      if(_unidadCaudal == "m³/h"){
        _valCaudal = _valVolumen * _valRenova;
        _valCaudalCFM = (_valCaudal / 1.7) ~/ _valCantEq;
      }else{
        _valCaudal = (_valVolumen * _valRenova) / 1.7;
        _valCaudalCFM = _valCaudal ~/ _valCantEq;
      }
      print(_valCaudalCFM);
    }
  });

  void _calcularPerdidasAdicionales() => setState(() {
    _valPerdAdi = _valAcce1 + _valAcce2 + _valAcce3 + _valAcce4;
  });
}
