diff --git a/TODO.md b/TODO.md index 41b07b9..46ae2b7 100644 --- a/TODO.md +++ b/TODO.md @@ -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. - 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 -- [ ] 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] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen +- [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 - [ ] 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. diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index a600de0..7ad4647 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -468,6 +468,18 @@ class _FormulaScreenState extends State { 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 { // Create a DerivedFormula with this input variable as output final derivedFormula = DerivedFormula( @@ -475,8 +487,8 @@ class _FormulaScreenState extends State { originalFormula: formula, ); - // Navigate to the new DerivedFormula screen - Navigator.push( + // Replace the current FormulaScreen with the new DerivedFormula screen + Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => FormulaScreen(