Created
February 3, 2025 00:15
-
-
Save diegoveloper/a4b4dfb442536c0bd9ca89aa9e0824f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
class TestAlgorithms extends StatefulWidget { | |
const TestAlgorithms({super.key}); | |
@override | |
State<TestAlgorithms> createState() => _TestAlgorithmsState(); | |
} | |
class _TestAlgorithmsState extends State<TestAlgorithms> { | |
final _controller = TextEditingController(); | |
int _numberOfDigits = 0; | |
void numberOfDigits(int number) { | |
// Problema: Contar la cantidad de dígitos de un número. | |
// | |
// Restricciones: | |
// - No se permite convertir el número a una cadena (String). | |
// - No se pueden utilizar logaritmos. | |
// - Solo se pueden emplear operaciones matemáticas básicas. | |
// | |
setState(() { | |
_numberOfDigits = 1; | |
}); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(24.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
const Text( | |
'Calcular cantidad de dígitos de: ', | |
style: TextStyle(fontSize: 20), | |
), | |
Padding( | |
padding: const EdgeInsets.symmetric(vertical: 8.0), | |
child: TextField( | |
controller: _controller, | |
inputFormatters: [ | |
FilteringTextInputFormatter.digitsOnly, | |
], | |
decoration: const InputDecoration( | |
border: OutlineInputBorder(), | |
labelText: 'Número', | |
), | |
), | |
), | |
Text( | |
'Cantidad de dígitos: $_numberOfDigits', | |
style: | |
const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), | |
), | |
MaterialButton( | |
color: Colors.blueAccent.withOpacity(0.5), | |
onPressed: () { | |
numberOfDigits(int.parse(_controller.text)); | |
}, | |
child: const Text('Calcular'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment