mirrored_repositories/gas_al
// ignore_for_file: prefer_final_fields, avoid_print

import 'package:flutter/material.dart';

class CampoTexto extends StatefulWidget {
  const CampoTexto({super.key});

  @override
  State<CampoTexto> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<CampoTexto> {
  TextEditingController _textEditingControllerAlcool = TextEditingController();
  TextEditingController _textEditingControllerGasolina =
      TextEditingController();

  String resultado = '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Padding(
          padding: EdgeInsets.all(8.0),
          child: Center(child: Text('Gasolina ou Álcool')),
        ),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: Column(
            children: [
              const SizedBox(
                height: 30,
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Image.asset('images/logo.png'),
              ),
              const SizedBox(
                height: 20,
              ),
              const Padding(
                padding: EdgeInsets.all(8.0),
                child: Text(
                  'Saiba qual a melhor opção para abastecimento do seu carro,economize dinheiro.',
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              const SizedBox(
                height: 20,
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: TextField(
                  keyboardType: TextInputType.number,
                  decoration: const InputDecoration(
                    labelText: 'Preço Álcool, ex: 1.59',
                  ),
                  style: const TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                  controller: _textEditingControllerAlcool,
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: TextField(
                  keyboardType: TextInputType.number,
                  decoration: const InputDecoration(
                    labelText: 'Preço Gasolina, ex: 3.59',
                  ),
                  style: const TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                  controller: _textEditingControllerGasolina,
                ),
              ),
              const SizedBox(
                height: 20,
              ),
              SizedBox(
                width: 200,
                height: 50,
                child: ElevatedButton(
                  onPressed: () {
                    double precoAlcool = double.parse(
                      _textEditingControllerAlcool.text.replaceAll(',', '.'),
                    );
                    double precoGasolina = double.parse(
                      _textEditingControllerGasolina.text.replaceAll(',', '.'),
                    );

                    double proporcao = precoAlcool / precoGasolina;

                    if (proporcao >= 0.7) {
                      resultado = 'Melhor abastecer com Gasolina';
                    } else {
                      resultado = 'Melhor abastecer com Álcool';
                    }
                  },
                  style: ElevatedButton.styleFrom(
                    foregroundColor: Colors.white,
                    backgroundColor: Colors.blue,
                    elevation: 5,
                  ),
                  child: const Text('Verificar'),
                ),
              ),
              const SizedBox(
                height: 20,
              ),
              Text(
                resultado,
                style: const TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
