release 1

This commit is contained in:
2026-04-09 16:26:05 +02:00
parent d9b88042cd
commit 4e2425c302
38 changed files with 194 additions and 157 deletions

View File

@@ -1,122 +1,209 @@
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
runApp(const SupermarketCalcApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class SupermarketCalcApp extends StatelessWidget {
const SupermarketCalcApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
title: 'Calc Margen',
debugShowCheckedModeBanner: false,
// Configuración Material You (M3)
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.red,
brightness: Brightness.light,
),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const HomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
State<HomePage> createState() => _HomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
class _HomePageState extends State<HomePage> {
final _costController = TextEditingController(text: "1.50");
final _marginController = TextEditingController(text: "40");
double _exactPrice = 2.10;
double _profit = 0.60;
String _suggestedPrice = "2.50 €";
@override
void initState() {
super.initState();
_calculate();
}
void _calculate() {
final double cost = double.tryParse(_costController.text) ?? 0;
final double marginPercent = double.tryParse(_marginController.text) ?? 0;
if (cost <= 0 || marginPercent <= 0) {
setState(() {
_suggestedPrice = "---";
});
return;
}
_profit = cost * (marginPercent / 100);
_exactPrice = cost + _profit;
// Lógica de Redondeo Psicológico (.50, .95, .99)
int floorPrice = _exactPrice.floor();
double finalVal;
if (_exactPrice <= 1) {
finalVal = (_exactPrice < 0.50) ? 0.99 : (_exactPrice.ceil() - 0.01);
} else {
if (_exactPrice <= floorPrice + 0.50) {
finalVal = floorPrice + 0.50;
} else if (_exactPrice <= floorPrice + 0.95) {
finalVal = floorPrice + 0.95;
} else {
finalVal = floorPrice + 0.99;
}
if (finalVal < _exactPrice) {
finalVal = _exactPrice.ceil() + 0.99;
}
}
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
_suggestedPrice = "${finalVal.toStringAsFixed(2)}";
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: colors.surface,
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
title: const Text("Calculadora de Margen"),
centerTitle: true,
backgroundColor: colors.surface,
elevation: 0,
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
body: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: .center,
children: [
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
// Card de entrada de datos
Card(
elevation: 0,
color: colors.surfaceContainerHighest.withOpacity(0.3),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
TextField(
controller: _costController,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
onChanged: (_) => _calculate(),
decoration: InputDecoration(
labelText: "Costo Base",
prefixText: "",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(16)),
filled: true,
fillColor: colors.surface,
),
),
const SizedBox(height: 16),
TextField(
controller: _marginController,
keyboardType: TextInputType.number,
onChanged: (_) => _calculate(),
decoration: InputDecoration(
labelText: "Margen Deseado",
suffixText: "%",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(16)),
filled: true,
fillColor: colors.surface,
),
),
],
),
),
),
const SizedBox(height: 24),
// Resultados Intermedios
Row(
children: [
_buildInfoTile("Precio Exacto", "${_exactPrice.toStringAsFixed(2)}", colors),
const SizedBox(width: 12),
_buildInfoTile("Ganancia", "${_profit.toStringAsFixed(2)}", colors),
],
),
const SizedBox(height: 24),
// Card de Resultado Final (Material You Hero)
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 16),
decoration: BoxDecoration(
color: colors.primaryContainer,
borderRadius: BorderRadius.circular(28),
),
child: Column(
children: [
Text(
"PRECIO SUGERIDO",
style: TextStyle(
color: colors.onPrimaryContainer,
fontWeight: FontWeight.w900,
letterSpacing: 1.2,
),
),
const SizedBox(height: 8),
Text(
_suggestedPrice,
style: TextStyle(
fontSize: 56,
fontWeight: FontWeight.bold,
color: colors.onPrimaryContainer,
),
),
Icon(Icons.auto_awesome, color: colors.primary, size: 30),
],
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
);
}
Widget _buildInfoTile(String label, String value, ColorScheme colors) {
return Expanded(
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: colors.outlineVariant),
borderRadius: BorderRadius.circular(20),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: TextStyle(fontSize: 12, color: colors.secondary)),
Text(value, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
],
),
),
);
}
}
}