import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:path_provider/path_provider.dart';

import '../../src/pages/pdf_viewer.dart';
import '../models/info_calculadora.dart';
import '../providers/archivos_provider.dart';

class ResultadoPage extends StatefulWidget {
  final List<String> frecuencias;
  final Map<String, double> arrLwFinal;
  final double sumaLogaritmicaLwFinal;
  final Map<String, double> arrLwA;
  final double sumaLogaritmicaLwA;
  final double presionSonora;
  final Map<String, double> arrSumaLog;
  final double sumaLogaritmicaLwFinalVa;
  final Map<String, double> arrEspectroResultante;
  final double sumaLogaritmicaLwAVa;
  final double presionSonoraVa;
  final Atenuacion arrAtenuador;
  final Map<String, String> arrDatosEntrada;
  final Map<String, String> arrConversiones;

  const ResultadoPage({
    Key? key,
    required this.frecuencias,
    required this.arrLwFinal,
    required this.sumaLogaritmicaLwFinal,
    required this.arrLwA,
    required this.sumaLogaritmicaLwA,
    required this.presionSonora,
    required this.arrSumaLog,
    required this.sumaLogaritmicaLwFinalVa,
    required this.arrEspectroResultante,
    required this.sumaLogaritmicaLwAVa,
    required this.presionSonoraVa,
    required this.arrAtenuador,
    required this.arrDatosEntrada,
    required this.arrConversiones,
  }) : super(key: key);

  @override
  State<ResultadoPage> createState() => _ResultadoPageState();
}

class _ResultadoPageState extends State<ResultadoPage> {
  final _archivosProvider = ArchivosProvider();
  int _decimales = 2;
  bool _firstState = true;
  late Row _headerFrecuenciasF;
  late Row _valuesFrecuenciasF;
  late Row _headerFrecuenciasS;
  late Row _valuesFrecuenciasS;
  late Row _valuesFrecuenciasT;
  late Row _valuesFrecuenciasC;
  late Row _datosAtenuadorSelec;
  String _jsonInfo = '';

  void _initTable(List<String> frecuencias, Map<String, double> arrLwFinal, double sumaLogaritmicaLwFinal,
      Map<String, double> arrLwA, double sumaLogaritmicaLwA, Map<String, double> arrSumaLog,
      double sumaLogaritmicaLwAtenuado, Map<String, double> arrEspectroResultante, double sumaLogaritmicaLwAVa,
      Atenuacion arrAtenuador){
    setState(() {
      _firstState = false;

      List<Widget> headerFrecuenciasF = [];
      List<Widget> valuesFrecuenciasF = [];
      List<Widget> headerFrecuenciasS = [];
      List<Widget> valuesFrecuenciasS = [];
      List<Widget> valuesFrecuenciasT = [];
      List<Widget> valuesFrecuenciasC = [];
      List<Widget> datosAtenuadorSelec = [];

      for(int i = 0; i < frecuencias.length; i++){
        headerFrecuenciasF.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  bottom: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            frecuencias[i],
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF333333),
                fontWeight: FontWeight.bold,
                fontSize: 24.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
        valuesFrecuenciasF.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  top: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            arrLwFinal[frecuencias[i]]!.toStringAsFixed(_decimales),
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF666666),
                fontSize: 20.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
        headerFrecuenciasS.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  bottom: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            frecuencias[i],
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF333333),
                fontWeight: FontWeight.bold,
                fontSize: 24.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
        valuesFrecuenciasS.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  top: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            arrLwA[frecuencias[i]]!.toStringAsFixed(_decimales),
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF666666),
                fontSize: 20.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
        valuesFrecuenciasT.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  top: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            arrSumaLog[frecuencias[i]]!.toStringAsFixed(_decimales),
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF666666),
                fontSize: 20.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
        valuesFrecuenciasC.add(Container(
          decoration: BoxDecoration(
              border: Border(
                  left: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: i == 0 ? 2.0 : 1.0
                  ),
                  right: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  ),
                  top: BorderSide(
                      color: Color(0xFFDDDDDD),
                      width: 1.0
                  )
              )
          ),
          child: Text(
            arrEspectroResultante[frecuencias[i]]!.toStringAsFixed(_decimales),
            textAlign: TextAlign.center,
            style: GoogleFonts.roboto(
                color: Color(0xFF666666),
                fontSize: 20.0
            ),
          ),
          padding: EdgeInsets.all(16.0),
          width: 150.0,
        ));
      }

      headerFrecuenciasF.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          'Lw (dB)',
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF333333),
              fontWeight: FontWeight.bold,
              fontSize: 24.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));
      valuesFrecuenciasF.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                top: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          sumaLogaritmicaLwFinal.toStringAsFixed(_decimales),
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));
      headerFrecuenciasS.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          'Lw (dBA)',
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF333333),
              fontWeight: FontWeight.bold,
              fontSize: 24.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));
      valuesFrecuenciasS.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                top: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          sumaLogaritmicaLwA.toStringAsFixed(_decimales),
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));
      valuesFrecuenciasT.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                top: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          sumaLogaritmicaLwAtenuado.toStringAsFixed(_decimales),
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));
      valuesFrecuenciasC.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                top: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                )
            )
        ),
        child: Text(
          sumaLogaritmicaLwAVa.toStringAsFixed(_decimales),
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
        padding: EdgeInsets.all(16.0),
        width: 150.0,
      ));

      datosAtenuadorSelec.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                )
            )
        ),
        width: 450.0,
        padding: EdgeInsets.all(16.0),
        child: Text(
          'Modelo',
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
      ));
      datosAtenuadorSelec.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                )
            )
        ),
        width: 300.0,
        padding: EdgeInsets.all(16.0),
        child: Text(
          arrAtenuador.modelo!,
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
      ));
      datosAtenuadorSelec.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                )
            )
        ),
        width: 450.0,
        padding: EdgeInsets.all(16.0),
        child: Text(
          'Longitud del atenuador',
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
      ));
      datosAtenuadorSelec.add(Container(
        decoration: BoxDecoration(
            border: Border(
                left: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 1.0
                ),
                right: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                ),
                bottom: BorderSide(
                    color: Color(0xFFDDDDDD),
                    width: 2.0
                )
            )
        ),
        width: 150.0,
        padding: EdgeInsets.all(16.0),
        child: Text(
          arrAtenuador.longitud!,
          textAlign: TextAlign.center,
          style: GoogleFonts.roboto(
              color: Color(0xFF666666),
              fontSize: 20.0
          ),
        ),
      ));

      _headerFrecuenciasF = Row(
        children: headerFrecuenciasF,
      );
      _valuesFrecuenciasF = Row(
        children: valuesFrecuenciasF,
      );
      _headerFrecuenciasS = Row(
        children: headerFrecuenciasS,
      );
      _valuesFrecuenciasS = Row(
        children: valuesFrecuenciasS,
      );
      _valuesFrecuenciasT = Row(
        children: valuesFrecuenciasT,
      );
      _valuesFrecuenciasC = Row(
        children: valuesFrecuenciasC,
      );
      _datosAtenuadorSelec = Row(
        children: datosAtenuadorSelec,
      );
    });
  }

  void showViewer(File document) {
    Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => PDFViewer(
          localFile: true,
          file: document,
        )
    ));
  }

  @override
  Widget build(BuildContext context) {
    if(_firstState){
      _initTable(widget.frecuencias, widget.arrLwFinal, widget.sumaLogaritmicaLwFinal,
          widget.arrLwA, widget.sumaLogaritmicaLwA, widget.arrSumaLog, widget.sumaLogaritmicaLwFinalVa,
          widget.arrEspectroResultante, widget.sumaLogaritmicaLwAVa, widget.arrAtenuador);
      _jsonInfo += '{"arrDatosDeEntrada":' + jsonEncode(widget.arrDatosEntrada) + ',';
      _jsonInfo += '"arrConversiones":' + jsonEncode(widget.arrConversiones) + ',';
      _jsonInfo += '"frecuencias":' + jsonEncode(widget.frecuencias) + ',';
      _jsonInfo += '"arrLwFinal":' + jsonEncode(widget.arrLwFinal) + ',';
      _jsonInfo += '"sumaLogaritmicaLwFinal":' + widget.sumaLogaritmicaLwFinal.toString() + ',';
      _jsonInfo += '"arrLwA":' + jsonEncode(widget.arrLwA) + ',';
      _jsonInfo += '"sumaLogaritmicaLwA":' + widget.sumaLogaritmicaLwA.toString() + ',';
      _jsonInfo += '"presionSonora":' + widget.presionSonora.toString() + ',';
      _jsonInfo += '"arrSumaLog":' + jsonEncode(widget.arrSumaLog) + ',';
      _jsonInfo += '"sumaLogaritmicaLwFinalVa":' + widget.sumaLogaritmicaLwFinalVa.toString() + ',';
      _jsonInfo += '"arrEspectroResultante":' + jsonEncode(widget.arrEspectroResultante) + ',';
      _jsonInfo += '"sumaLogaritmicaLwAVa":' + widget.sumaLogaritmicaLwAVa.toString() + ',';
      _jsonInfo += '"presionSonoraVa":' + widget.presionSonoraVa.toString() + ',';
      _jsonInfo += '"modelo":"' + widget.arrAtenuador.modelo! + '",';
      _jsonInfo += '"longitud":' + widget.arrAtenuador.longitud! + '}';

      _jsonInfo = _jsonInfo.replaceAll('##', '%%');
      _jsonInfo = base64Encode(utf8.encode(_jsonInfo));
    }
    return Scaffold(
      appBar: AppBar(
        actions: [
          IconButton(
            icon: Icon(
              Icons.picture_as_pdf,
              color: Colors.white,
            ),
            onPressed: (){
              Fluttertoast.showToast(
                  msg: 'Abriendo PDF...',
                  toastLength: Toast.LENGTH_LONG,
                  gravity: ToastGravity.CENTER,
                  timeInSecForIosWeb: 1
              );
              _archivosProvider.fetchAtenuador(_jsonInfo).then((archivo){
                _createFileFromString(archivo.data!, archivo.name!).then((name){
                  print("==DIRECTORIO: ${name.path}===");
                  showViewer(name);
                });
              });
            },
          )
        ],
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Column(
              children: [
                Container(
                  width: 1350.0,
                  child: Text(
                    'Espectro de Potencia Sonora Ventilador Lw',
                    textAlign: TextAlign.center,
                    style: GoogleFonts.roboto(
                        color: Color(0xFF333333),
                        fontSize: 24.0,
                        fontWeight: FontWeight.bold
                    ),
                  ),
                  margin: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0),
                  padding: EdgeInsets.all(16.0),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: Color(0xFFDDDDDD),
                          width: 2.0
                      )
                  ),
                ),
                _headerFrecuenciasF,
                _valuesFrecuenciasF,
                Container(
                  width: 1350.0,
                  child: Text(
                    'Espectro de Potencia Sonora Ventilador Ponderación A Lw(A)',
                    textAlign: TextAlign.center,
                    style: GoogleFonts.roboto(
                        color: Color(0xFF333333),
                        fontSize: 24.0,
                        fontWeight: FontWeight.bold
                    ),
                  ),
                  margin: EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
                  padding: EdgeInsets.all(16.0),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: Color(0xFFDDDDDD),
                          width: 2.0
                      )
                  ),
                ),
                _headerFrecuenciasS,
                _valuesFrecuenciasS,
                Row(
                  children: [
                    Container(
                      padding: EdgeInsets.all(16.0),
                      decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              top: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              right: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 1.0
                              )
                          )
                      ),
                      width: 450.0,
                      child: Text(
                        'Presión Sonora',
                        textAlign: TextAlign.center,
                        style: GoogleFonts.roboto(
                            color: Color(0xFF333333),
                            fontSize: 24.0,
                            fontWeight: FontWeight.bold
                        ),
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.all(16.0),
                      decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 1.0
                              ),
                              top: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              right: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              )
                          )
                      ),
                      width: 900.0,
                      child: Text(
                        widget.presionSonora.toStringAsFixed(_decimales),
                        textAlign: TextAlign.center,
                        style: GoogleFonts.roboto(
                            color: Color(0xFF333333),
                            fontSize: 24.0,
                            fontWeight: FontWeight.bold
                        ),
                      ),
                    )
                  ],
                ),
                Container(
                  width: 1350.0,
                  child: Text(
                    'Espectro de Potencia Sonora Ventilador con Atenuador Lw',
                    textAlign: TextAlign.center,
                    style: GoogleFonts.roboto(
                        color: Color(0xFF333333),
                        fontSize: 24.0,
                        fontWeight: FontWeight.bold
                    ),
                  ),
                  margin: EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
                  padding: EdgeInsets.all(16.0),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: Color(0xFFDDDDDD),
                          width: 2.0
                      )
                  ),
                ),
                _headerFrecuenciasS,
                _valuesFrecuenciasT,
                Container(
                  width: 1350.0,
                  child: Text(
                    'Espectro de Potencia Sonora Ventilador con Atenuador Lw(A)',
                    textAlign: TextAlign.center,
                    style: GoogleFonts.roboto(
                        color: Color(0xFF333333),
                        fontSize: 24.0,
                        fontWeight: FontWeight.bold
                    ),
                  ),
                  margin: EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
                  padding: EdgeInsets.all(16.0),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: Color(0xFFDDDDDD),
                          width: 2.0
                      )
                  ),
                ),
                _headerFrecuenciasS,
                _valuesFrecuenciasC,
                Row(
                  children: [
                    Container(
                      padding: EdgeInsets.all(16.0),
                      decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              top: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              right: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 1.0
                              )
                          )
                      ),
                      width: 450.0,
                      child: Text(
                        'Presión Sonora',
                        textAlign: TextAlign.center,
                        style: GoogleFonts.roboto(
                            color: Color(0xFF333333),
                            fontSize: 24.0,
                            fontWeight: FontWeight.bold
                        ),
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.all(16.0),
                      decoration: BoxDecoration(
                          border: Border(
                              left: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 1.0
                              ),
                              top: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              ),
                              right: BorderSide(
                                  color: Color(0xFFDDDDDD),
                                  width: 2.0
                              )
                          )
                      ),
                      width: 900.0,
                      child: Text(
                        widget.presionSonoraVa.toStringAsFixed(_decimales),
                        textAlign: TextAlign.center,
                        style: GoogleFonts.roboto(
                            color: Color(0xFF333333),
                            fontSize: 24.0,
                            fontWeight: FontWeight.bold
                        ),
                      ),
                    )
                  ],
                ),
                Container(
                  width: 1350.0,
                  child: Text(
                    'Datos del Atenuador Seleccionado',
                    textAlign: TextAlign.center,
                    style: GoogleFonts.roboto(
                        color: Color(0xFF333333),
                        fontSize: 24.0,
                        fontWeight: FontWeight.bold
                    ),
                  ),
                  margin: EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.0),
                  padding: EdgeInsets.all(16.0),
                  decoration: BoxDecoration(
                      border: Border.all(
                          color: Color(0xFFDDDDDD),
                          width: 2.0
                      )
                  ),
                ),
                _datosAtenuadorSelec,
                SizedBox(height: 8.0),

              ],
            ),
          ),
        ),
      ),
    );
  }

  Future<File> _createFileFromString(String encoded, String name) async{
    Uint8List bytes = base64Decode(encoded);
    String dir = (await getApplicationDocumentsDirectory()).path;
    File file = File(
        "$dir/$name"
    );
    await file.writeAsBytes(bytes);
    return file;
  }
}
