better witdh and price comparation formula
This commit is contained in:
parent
76abe6d762
commit
f43d2bcce3
2 changed files with 72 additions and 76 deletions
|
|
@ -152,7 +152,7 @@ Where:
|
||||||
,
|
,
|
||||||
{
|
{
|
||||||
"name": "Compare price per mass",
|
"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": [
|
"input": [
|
||||||
{"name": "price1", "unit": "currency"},
|
{"name": "price1", "unit": "currency"},
|
||||||
{"name": "mass1", "unit": "kilogram"},
|
{"name": "mass1", "unit": "kilogram"},
|
||||||
|
|
@ -164,11 +164,11 @@ Where:
|
||||||
var p1 = price1 / mass1;
|
var p1 = price1 / mass1;
|
||||||
var p2 = price2 / mass2;
|
var p2 = price2 / mass2;
|
||||||
if (p1 < p2) {
|
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) {
|
} 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 {
|
} 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"]
|
"tags": ["comparison", "shopping", "economics"]
|
||||||
|
|
|
||||||
|
|
@ -251,10 +251,17 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(widget.formula.output.name),
|
// Fixed width for field name
|
||||||
const Spacer(),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 150,
|
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(
|
child: TextFormField(
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
@ -291,12 +298,19 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(variable.name),
|
// Fixed width for field name
|
||||||
const Spacer(),
|
|
||||||
if (isCategorical) ...[
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 150,
|
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],
|
value: _selectedValues[variable.name],
|
||||||
items: variable.values!
|
items: variable.values!
|
||||||
.map((v) => DropdownMenuItem<String>(value: v, child: Text(v)))
|
.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';
|
if (value == null || value.isEmpty) return 'Required';
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
),
|
: TextFormField(
|
||||||
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(
|
|
||||||
controller: _inputControllers[variable.name],
|
controller: _inputControllers[variable.name],
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
inputFormatters: [
|
inputFormatters: [
|
||||||
|
|
@ -364,7 +361,6 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue