feat: enable auto-calculation with real-time input updates
Co-authored-by: aider (openrouter/deepseek/deepseek-r1:free) <aider@aider.chat>
This commit is contained in:
parent
5e2acf39c3
commit
54e40a2abc
1 changed files with 8 additions and 16 deletions
|
|
@ -30,18 +30,20 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// Initialize controllers and units
|
// Initialize controllers and units with listeners
|
||||||
for (final input in widget.formula.input) {
|
for (final input in widget.formula.input) {
|
||||||
_inputControllers[input.name] = TextEditingController();
|
_inputControllers[input.name] = TextEditingController();
|
||||||
_selectedUnits[input.name] = input.magnitude;
|
_selectedUnits[input.name] = input.magnitude;
|
||||||
|
_inputControllers[input.name]!.addListener(_evaluateFormula);
|
||||||
}
|
}
|
||||||
_selectedOutputUnit = widget.formula.output.magnitude;
|
_selectedOutputUnit = widget.formula.output.magnitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// Clean up controllers
|
// Clean up controllers and listeners
|
||||||
for (final controller in _inputControllers.values) {
|
for (final controller in _inputControllers.values) {
|
||||||
|
controller.removeListener(_evaluateFormula);
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
@ -105,21 +107,11 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Column(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
_buildInputSection(),
|
||||||
child: ListView(
|
const SizedBox(height: 24),
|
||||||
children: [
|
_buildOutputSection(),
|
||||||
_buildInputSection(),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
_buildOutputSection(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _evaluateFormula,
|
|
||||||
child: const Text('Calculate'),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue