diff --git a/assets/formulas/formulas.d4rt b/assets/formulas/formulas.d4rt index 7291928..2646d8a 100644 --- a/assets/formulas/formulas.d4rt +++ b/assets/formulas/formulas.d4rt @@ -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"] diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index 6a35b9c..f155039 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -251,10 +251,17 @@ class _FormulaScreenState extends State { 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,79 +298,68 @@ class _FormulaScreenState extends State { padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row( children: [ - Text(variable.name), - const Spacer(), - if (isCategorical) ...[ - SizedBox( - width: 150, - child: DropdownButtonFormField( - value: _selectedValues[variable.name], - items: variable.values! - .map((v) => DropdownMenuItem(value: v, child: Text(v))) - .toList(), - onChanged: (v) { - _selectedValues[variable.name] = v; - _evaluateFormula(); - setState(() { - }); - }, - decoration: const InputDecoration( - border: UnderlineInputBorder(), - ), - validator: (value) { - if (value == null || value.isEmpty) return 'Required'; - return null; - }, - ), + // Fixed width for field name + SizedBox( + width: 150, + child: Text( + variable.name, + overflow: TextOverflow.ellipsis, ), - const SizedBox(width: 8), - if (variable.unit != null) - UnitDropdown( - corpus: widget.corpus, - variable: variable, - selectedUnit: _selectedUnits[variable.name], - onUnitChanged: (unit) { + ), + const SizedBox(width: 8), // Add some spacing + // Flexible space for input field + Expanded( + child: isCategorical + ? DropdownButtonFormField( + value: _selectedValues[variable.name], + items: variable.values! + .map((v) => DropdownMenuItem(value: v, child: Text(v))) + .toList(), + onChanged: (v) { + _selectedValues[variable.name] = v; + _evaluateFormula(); + setState(() { + }); + }, + decoration: const InputDecoration( + border: UnderlineInputBorder(), + ), + validator: (value) { + if (value == null || value.isEmpty) return 'Required'; + return null; + }, + ) + : TextFormField( + controller: _inputControllers[variable.name], + keyboardType: TextInputType.number, + inputFormatters: [ + //FilteringTextInputFormatter.allow(RegExp(r'[0-9\.\-]')), + ], + decoration: const InputDecoration( + border: UnderlineInputBorder(), + ), + autovalidateMode: AutovalidateMode.always, + validator: (value) { + if (value == null || value.isEmpty) { + return 'Required'; + } + return _inputControllers[variable.name]!.lastError; + }, + ), + ), + const SizedBox(width: 8), + if (variable.unit != null) + UnitDropdown( + corpus: widget.corpus, + variable: variable, + selectedUnit: _selectedUnits[variable.name], + onUnitChanged: (unit) { + setState(() { _selectedUnits[variable.name] = unit; - _evaluateFormula(); - setState(() { - }); - }, - ), - ] else ...[ - SizedBox( - width: 100, - child: TextFormField( - controller: _inputControllers[variable.name], - keyboardType: TextInputType.number, - inputFormatters: [ - //FilteringTextInputFormatter.allow(RegExp(r'[0-9\.\-]')), - ], - decoration: const InputDecoration( - border: UnderlineInputBorder(), - ), - autovalidateMode: AutovalidateMode.always, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Required'; - } - return _inputControllers[variable.name]!.lastError; - }, - ), + }); + _evaluateFormula(); + }, ), - const SizedBox(width: 8), - if (variable.unit != null) - UnitDropdown( - corpus: widget.corpus, - variable: variable, - selectedUnit: _selectedUnits[variable.name], - onUnitChanged: (unit) { - setState(() { - _selectedUnits[variable.name] = unit; - }); - _evaluateFormula(); - }, - ), - ], ], ), );