saved formulas

This commit is contained in:
Álvaro González 2026-02-28 19:35:47 +01:00
parent 9c8afe739d
commit db83c6ecc2
3 changed files with 6 additions and 13 deletions

View file

@ -47,3 +47,5 @@
- [R] There is one row for the ouput variable, similar to the row for the input variable - [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] 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] 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

View file

@ -8,12 +8,10 @@ import 'package:share_plus/share_plus.dart';
class FormulaList extends StatefulWidget { class FormulaList extends StatefulWidget {
final Corpus corpus; final Corpus corpus;
final List<Formula> formulas;
const FormulaList({ const FormulaList({
super.key, super.key,
required this.corpus, required this.corpus,
required this.formulas,
}); });
@override @override
@ -43,9 +41,9 @@ class _FormulaListState extends State<FormulaList> {
} }
List<Formula> get _filteredFormulas { List<Formula> 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 nameMatch = formula.name.toLowerCase().contains(_searchQuery);
final tagMatch = formula.tags.any((tag) => tag.toLowerCase().contains(_searchQuery)); final tagMatch = formula.tags.any((tag) => tag.toLowerCase().contains(_searchQuery));
return nameMatch || tagMatch; return nameMatch || tagMatch;
@ -80,12 +78,6 @@ class _FormulaListState extends State<FormulaList> {
builder: (context) => FormulaEditor( builder: (context) => FormulaEditor(
formula: formula, formula: formula,
corpus: widget.corpus, 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<FormulaList> {
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text('Error'), title: const Text('Error'),
content: Text(message), content: Text(message),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: Text('OK'), child: const Text('OK'),
), ),
], ],
); );

View file

@ -58,7 +58,6 @@ class _CorpusLoaderState extends State<CorpusLoader> {
appBar: AppBar(title: const Text('Formulas')), appBar: AppBar(title: const Text('Formulas')),
body: FormulaList( body: FormulaList(
corpus: snapshot.data!, corpus: snapshot.data!,
formulas: snapshot.data!.getFormulas(),
), ),
); );
} }