better witdh and price comparation formula

This commit is contained in:
Your Name 2026-02-07 12:39:26 +01:00
parent 76abe6d762
commit f43d2bcce3
2 changed files with 72 additions and 76 deletions

View file

@ -152,7 +152,7 @@ Where:
,
{
"name": "Compare price per mass",
"description": "Compares two products by their price per mass and returns which is cheaper.",
"description": "Compares two products by their price per mass and returns which is cheaper, including price per kg for each product.",
"input": [
{"name": "price1", "unit": "currency"},
{"name": "mass1", "unit": "kilogram"},
@ -164,11 +164,11 @@ Where:
var p1 = price1 / mass1;
var p2 = price2 / mass2;
if (p1 < p2) {
Result = 'first product is cheaper';
Result = 'first product is cheaper at \${p1.toStringAsFixed(2)} currency/kg vs \${p2.toStringAsFixed(2)} currency/kg';
} else if (p2 < p1) {
Result = 'second product is cheaper';
Result = 'second product is cheaper at \${p2.toStringAsFixed(2)} currency/kg vs \${p1.toStringAsFixed(2)} currency/kg';
} else {
Result = 'both products have the same price per mass';
Result = 'both products have the same price per mass at \${p1.toStringAsFixed(2)} currency/kg';
}
""",
"tags": ["comparison", "shopping", "economics"]

View file

@ -251,10 +251,17 @@ class _FormulaScreenState extends State<FormulaScreen> {
const SizedBox(height: 8),
Row(
children: [
Text(widget.formula.output.name),
const Spacer(),
// Fixed width for field name
SizedBox(
width: 150,
child: Text(
widget.formula.output.name,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8), // Add some spacing
// Flexible space for result field
Expanded(
child: TextFormField(
readOnly: true,
enabled: false,
@ -291,12 +298,19 @@ class _FormulaScreenState extends State<FormulaScreen> {
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Text(variable.name),
const Spacer(),
if (isCategorical) ...[
// Fixed width for field name
SizedBox(
width: 150,
child: DropdownButtonFormField<String>(
child: Text(
variable.name,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8), // Add some spacing
// Flexible space for input field
Expanded(
child: isCategorical
? DropdownButtonFormField<String>(
value: _selectedValues[variable.name],
items: variable.values!
.map((v) => DropdownMenuItem<String>(value: v, child: Text(v)))
@ -314,25 +328,8 @@ class _FormulaScreenState extends State<FormulaScreen> {
if (value == null || value.isEmpty) return 'Required';
return null;
},
),
),
const SizedBox(width: 8),
if (variable.unit != null)
UnitDropdown(
corpus: widget.corpus,
variable: variable,
selectedUnit: _selectedUnits[variable.name],
onUnitChanged: (unit) {
_selectedUnits[variable.name] = unit;
_evaluateFormula();
setState(() {
});
},
),
] else ...[
SizedBox(
width: 100,
child: TextFormField(
)
: TextFormField(
controller: _inputControllers[variable.name],
keyboardType: TextInputType.number,
inputFormatters: [
@ -364,7 +361,6 @@ class _FormulaScreenState extends State<FormulaScreen> {
},
),
],
],
),
);
}