79739051

Date: 2025-08-18 17:04:15
Score: 0.5
Natty:
Report link

import 'package:flutter/material.dart';

class ConversionPage extends StatefulWidget {

@override

_ConversionPageState createState() => _ConversionPageState();

}

class _ConversionPageState extends State<ConversionPage> {

double inputValue = 0;

String fromUnit = 'metros';

String toUnit = 'pies';

double result = 0;

final Map<String, double> lengthFactors = {

'metros': 1.0,

'pies': 3.2808,

'centímetros': 100.0,

'pulgadas': 39.3701,

};

void convert() {

double base = inputValue / lengthFactors\[fromUnit\]!;

setState(() {

  result = base \* lengthFactors\[toUnit\]!;

});

}

@override

Widget build(BuildContext context) {

return Scaffold(

  appBar: AppBar(title: Text('ConvertiTodo')),

  body: Padding(

    padding: EdgeInsets.all(16),

    child: Column(

      children: \[

        TextField(

          keyboardType: TextInputType.number,

          decoration: InputDecoration(labelText: 'Valor'),

          onChanged: (value) {

            inputValue = double.tryParse(value) ?? 0;

            convert();

          },

        ),

        DropdownButton\<String\>(

          value: fromUnit,

          items: lengthFactors.keys.map((unit) {

            return DropdownMenuItem(value: unit, child: Text(unit));

          }).toList(),

          onChanged: (value) {

            fromUnit = value!;

            convert();

          },

        ),

        DropdownButton\<String\>(

          value: toUnit,

          items: lengthFactors.keys.map((unit) {

            return DropdownMenuItem(value: unit, child: Text(unit));

          }).toList(),

          onChanged: (value) {

            toUnit = value!;

            convert();

          },

        ),

        SizedBox(height: 20),

        Text('Resultado: $result $toUnit', style: TextStyimport 'package:flutter/material.dart';

class ConversionPage extends StatefulWidget {

@override

_ConversionPageState createState() => _ConversionPageState();

}

class _ConversionPageState extends State<ConversionPage> {

double inputValue = 0;

String fromUnit = 'metros';

String toUnit = 'pies';

double result = 0;

final Map<String, double> lengthFactors = {

'metros': 1.0,

'pies': 3.2808,

'centímetros': 100.0,

'pulgadas': 39.3701,

};

void convert() {

double base = inputValue / lengthFactors\[fromUnit\]!;

setState(() {

  result = base \* lengthFactors\[toUnit\]!;

});

}

@override

Widget build(BuildContext context) {

return Scaffold(

  appBar: AppBar(title: Text('ConvertiTodo')),

  body: Padding(

    padding: EdgeInsets.all(16),

    child: Column(

      children: \[

        TextField(

          keyboardType: TextInputType.number,

          decoration: InputDecoration(labelText: 'Valor'),

          onChanged: (value) {

            inputValue = double.tryParse(value) ?? 0;

            convert();

          },

        ),

        DropdownButton\<String\>(

          value: fromUnit,

          items: lengthFactors.keys.map((unit) {

            return DropdownMenuItem(value: unit, child: Text(unit));

          }).toList(),

          onChanged: (value) {

            fromUnit = value!;

            convert();

          },

        ),

        DropdownButton\<String\>(

          value: toUnit,

          items: lengthFactors.keys.map((unit) {

            return DropdownMenuItem(value: unit, child: Text(unit));

          }).toList(),

          onChanged: (value) {

            toUnit = value!;

            convert();

          },

        ),

        SizedBox(height: 20),

        Text('Resultado: $result $toUnit', style: TextStyle(fontSize: 20)),

      \],

    ),

  ),

);

}

}le(fontSize: 20)),

      \],

    ),

  ),

);

}

}

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @override
  • User mentioned (0): @override
  • User mentioned (0): @override
  • User mentioned (0): @override
  • Low reputation (1):
Posted by: Johana Tezen