diff --git a/TODO.md b/TODO.md index 8b6f6af..4a4ce85 100644 --- a/TODO.md +++ b/TODO.md @@ -47,3 +47,5 @@ - [R] There is one row for the ouput variable, similar to the row for the input variable - [R] d4rtCode is a text area with dart syntax highligthing - [R] At the botton, a button allows to test the edited Formula, launching a FormulaScreen +- [R] When FormulaEditor._save formula, ensure formula is updated in the initial FormulaList +- [ ] Refresh FormulaList each time it gets focus, so formulas are updated from corpus diff --git a/lib/ai/formula_list.dart b/lib/ai/formula_list.dart index a7041c0..42abf8a 100644 --- a/lib/ai/formula_list.dart +++ b/lib/ai/formula_list.dart @@ -8,12 +8,10 @@ import 'package:share_plus/share_plus.dart'; class FormulaList extends StatefulWidget { final Corpus corpus; - final List formulas; const FormulaList({ super.key, required this.corpus, - required this.formulas, }); @override @@ -43,9 +41,9 @@ class _FormulaListState extends State { } List get _filteredFormulas { - if (_searchQuery.isEmpty) return widget.formulas; + if (_searchQuery.isEmpty) return widget.corpus.getFormulas(); - return widget.formulas.where((formula) { + return widget.corpus.getFormulas().where((formula) { final nameMatch = formula.name.toLowerCase().contains(_searchQuery); final tagMatch = formula.tags.any((tag) => tag.toLowerCase().contains(_searchQuery)); return nameMatch || tagMatch; @@ -80,12 +78,6 @@ class _FormulaListState extends State { builder: (context) => FormulaEditor( formula: formula, corpus: widget.corpus, - onSave: (updatedFormula) { - // Refresh the formula list after saving - setState(() { - // The corpus has been updated, so we just need to rebuild - }); - }, ), ), ); @@ -122,14 +114,14 @@ class _FormulaListState extends State { context: context, builder: (BuildContext context) { return AlertDialog( - title: Text('Error'), + title: const Text('Error'), content: Text(message), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, - child: Text('OK'), + child: const Text('OK'), ), ], ); diff --git a/lib/main.dart b/lib/main.dart index da4781c..9455143 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -58,7 +58,6 @@ class _CorpusLoaderState extends State { appBar: AppBar(title: const Text('Formulas')), body: FormulaList( corpus: snapshot.data!, - formulas: snapshot.data!.getFormulas(), ), ); }