better derived formula management

This commit is contained in:
Álvaro González 2026-03-10 18:15:07 +01:00
parent e4f79ccab6
commit 72435341a9
2 changed files with 16 additions and 4 deletions

View file

@ -64,7 +64,7 @@
- This button will create a DerivedFormula, with the input variable as output, and the rest of the input variables as inputs. - This button will create a DerivedFormula, with the input variable as output, and the rest of the input variables as inputs.
- The DerivedFormula will then be displayed in the FormulaScreen - The DerivedFormula will then be displayed in the FormulaScreen
- [R] If the Formula displayed in FormulaScreen is a DerivedFormula, the edit button will be disabled - [R] If the Formula displayed in FormulaScreen is a DerivedFormula, the edit button will be disabled
- [ ] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen - [R] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen
- [ ] In FormulaScreen, a Formula cant be derived if DerivedFormula.isDerivable() returns false - [R] In FormulaScreen, a Formula cant be derived if DerivedFormula.isDerivable() returns false
- [ ] The algorithm of formulaSolver should be https://en.wikipedia.org/wiki/Newton%27s_method - [ ] The algorithm of formulaSolver should be https://en.wikipedia.org/wiki/Newton%27s_method
- [ ] Add a uuid column to the table or FormulaElements, so it is not necessary to load all the formulas to find a formula by uuid. This will improve performance when updating and deleting. - [ ] Add a uuid column to the table or FormulaElements, so it is not necessary to load all the formulas to find a formula by uuid. This will improve performance when updating and deleting.

View file

@ -468,6 +468,18 @@ class _FormulaScreenState extends State<FormulaScreen> {
return; return;
} }
// Check if the formula can be derived
if (!DerivedFormula.isDerivable(formula)) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('This formula cannot be derived because it contains non number variables'),
duration: Duration(seconds: 2),
),
);
return;
}
try { try {
// Create a DerivedFormula with this input variable as output // Create a DerivedFormula with this input variable as output
final derivedFormula = DerivedFormula( final derivedFormula = DerivedFormula(
@ -475,8 +487,8 @@ class _FormulaScreenState extends State<FormulaScreen> {
originalFormula: formula, originalFormula: formula,
); );
// Navigate to the new DerivedFormula screen // Replace the current FormulaScreen with the new DerivedFormula screen
Navigator.push( Navigator.pushReplacement(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => FormulaScreen( builder: (context) => FormulaScreen(