From daebfeb3852395d28a18796c5deb9ab848975ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Gonz=C3=A1lez?= Date: Thu, 19 Mar 2026 12:05:10 +0100 Subject: [PATCH] Changed icons and other minor changes --- lib/ai/formula_list.dart | 39 +------ lib/ai/formula_screen.dart | 15 ++- lib/ai/import_preview_screen.dart | 174 ++++++++++-------------------- lib/main.dart | 2 +- 4 files changed, 63 insertions(+), 167 deletions(-) diff --git a/lib/ai/formula_list.dart b/lib/ai/formula_list.dart index bfd4caf..bc4aa37 100644 --- a/lib/ai/formula_list.dart +++ b/lib/ai/formula_list.dart @@ -81,23 +81,6 @@ class _FormulaListState extends State { } } - void _editFormula(Formula formula) { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => FormulaEditor( - formula: formula, - corpus: widget.corpus, - onSave: (updatedFormula){ - setState((){ - // THIS UPDATES THE FORMULA LIST - }); - } - ), - ), - ); - } - void _copyFormula(Formula formula) async { try { final exportString = _formulaAndDependenciesToExportStringLiteral(formula); @@ -137,22 +120,6 @@ class _FormulaListState extends State { ); } - void _importFromText() { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => ImportFromTextScreen( - corpus: widget.corpus, - ), - ), - ).then((result) { - if (result == true) { - setState(() { - // Refresh the list when returning from import - }); - } - }); - } @override Widget build(BuildContext context) { @@ -183,13 +150,9 @@ class _FormulaListState extends State { trailing: Row( mainAxisSize: MainAxisSize.min, children: [ - IconButton( - icon: const Icon(Icons.edit), - onPressed: () => _editFormula(formula), - tooltip: 'Edit Formula', - ), PopupMenuButton( icon: const Icon(Icons.share), + tooltip: 'Share or copy to clipboard', onSelected: (value) { if (value == 'share') { _shareFormula(formula); diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index 3d69408..159e0fd 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -121,14 +121,13 @@ class _FormulaScreenState extends State { } late final dynamic result; - //if( formula is DerivedFormula) { + if( formula is DerivedFormula) { result = formulaSolver(formula, formula.output.name, inputValues,); - //} - //else { - // TODO: MAYBE ONLY FORMULASOLVER IS NECCESSARY" - //final evaluator = FormulaEvaluator(); - //result = evaluator.evaluate(formula as Formula, inputValues); - //} + } + else { + final evaluator = FormulaEvaluator(); + result = evaluator.evaluate(formula as Formula, inputValues); + } // Convert output to selected unit if needed String? unit = formula.output.unit; @@ -342,7 +341,7 @@ class _FormulaScreenState extends State { children: [ // Fixed width for field name SizedBox( - width: 150, + width: 50, child: Text( formula.output.name, overflow: TextOverflow.ellipsis, diff --git a/lib/ai/import_preview_screen.dart b/lib/ai/import_preview_screen.dart index be9a11f..efb5288 100644 --- a/lib/ai/import_preview_screen.dart +++ b/lib/ai/import_preview_screen.dart @@ -5,7 +5,6 @@ import 'package:d4rt_formulas/corpus.dart'; import 'package:d4rt_formulas/ai/formula_editor.dart'; import 'package:d4rt_formulas/services/import_service.dart'; - import 'package:flutter_code_editor/flutter_code_editor.dart'; import 'package:flutter_highlight/themes/monokai-sublime.dart'; import 'package:highlight/languages/dart.dart'; @@ -15,11 +14,7 @@ class ImportPreviewScreen extends StatefulWidget { final List elements; final Corpus corpus; - const ImportPreviewScreen({ - super.key, - required this.elements, - required this.corpus, - }); + const ImportPreviewScreen({super.key, required this.elements, required this.corpus}); @override State createState() => _ImportPreviewScreenState(); @@ -52,9 +47,7 @@ class _ImportPreviewScreenState extends State { onSave: (updatedFormula) { // Update the element in the list setState(() { - final index = widget.elements.indexWhere( - (e) => e is Formula && e.uuid == updatedFormula.uuid, - ); + final index = widget.elements.indexWhere((e) => e is Formula && e.uuid == updatedFormula.uuid); if (index != -1) { widget.elements[index] = updatedFormula; } @@ -77,33 +70,27 @@ class _ImportPreviewScreenState extends State { }).toList(); if (selectedElements.isEmpty) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('No elements selected to import'), - backgroundColor: Colors.orange, - ), - ); + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text('No elements selected to import'), backgroundColor: Colors.orange)); return; } try { widget.corpus.loadFormulaElements(selectedElements, true); - + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Imported ${selectedElements.length} element(s) successfully'), backgroundColor: Colors.green, ), ); - + Navigator.pop(context, true); } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text('Error importing: $e'), - backgroundColor: Colors.red, - ), - ); + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('Error importing: $e'), backgroundColor: Colors.red)); } } @@ -115,23 +102,14 @@ class _ImportPreviewScreenState extends State { return Scaffold( appBar: AppBar( title: const Text('Import Preview'), - actions: [ - IconButton( - icon: const Icon(Icons.check), - tooltip: 'Import Selected', - onPressed: _importSelected, - ), - ], + actions: [IconButton(icon: const Icon(Icons.check), tooltip: 'Import Selected', onPressed: _importSelected)], ), body: Column( children: [ if (formulas.isEmpty && units.isEmpty) const Padding( padding: EdgeInsets.all(16.0), - child: Text( - 'No formula elements found in the shared content', - style: TextStyle(fontSize: 16), - ), + child: Text('No formula elements found in the shared content', style: TextStyle(fontSize: 16)), ) else Expanded( @@ -139,25 +117,13 @@ class _ImportPreviewScreenState extends State { children: [ if (formulas.isNotEmpty) ...[ const ListTile( - title: Text( - 'Formulas', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), + title: Text('Formulas', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), ), ...formulas.map((formula) => _buildFormulaTile(formula)), ], if (units.isNotEmpty) ...[ const ListTile( - title: Text( - 'Units', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), + title: Text('Units', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), ), ...units.map((unit) => _buildUnitTile(unit)), ], @@ -171,7 +137,7 @@ class _ImportPreviewScreenState extends State { Widget _buildFormulaTile(Formula formula) { final isSelected = _selectedUuids.contains(formula.uuid); - + return Card( margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), child: ListTile( @@ -189,9 +155,7 @@ class _ImportPreviewScreenState extends State { ), title: Text(formula.name), subtitle: Text( - formula.description?.isNotEmpty == true - ? formula.description!.split('\n').first - : 'No description', + formula.description?.isNotEmpty == true ? formula.description!.split('\n').first : 'No description', maxLines: 2, overflow: TextOverflow.ellipsis, ), @@ -199,21 +163,22 @@ class _ImportPreviewScreenState extends State { mainAxisSize: MainAxisSize.min, children: [ if (formula.tags.isNotEmpty) - Wrap( - spacing: 4, - children: formula.tags.take(3).map((tag) { - return Chip( - label: Text(tag, style: const TextStyle(fontSize: 10)), - padding: EdgeInsets.zero, - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - ); - }).toList(), + SingleChildScrollView( + child: SizedBox( + width: 150, + child: Wrap( + spacing: 4, + children: formula.tags.take(10).map((tag) { + return Chip( + label: Text(tag, style: const TextStyle(fontSize: 10)), + padding: EdgeInsets.zero, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + ); + }).toList(), + ), + ), ), - IconButton( - icon: const Icon(Icons.edit), - tooltip: 'Edit', - onPressed: () => _editFormulaElement(formula), - ), + IconButton(icon: const Icon(Icons.edit), tooltip: 'Edit', onPressed: () => _editFormulaElement(formula)), ], ), ), @@ -222,7 +187,7 @@ class _ImportPreviewScreenState extends State { Widget _buildUnitTile(UnitSpec unit) { final isSelected = _selectedUuids.contains(unit.name); - + return Card( margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), child: ListTile( @@ -249,20 +214,14 @@ class _ImportPreviewScreenState extends State { class ImportFromTextScreen extends StatefulWidget { final Corpus corpus; - const ImportFromTextScreen({ - super.key, - required this.corpus, - }); + const ImportFromTextScreen({super.key, required this.corpus}); @override State createState() => _ImportFromTextScreenState(); } class _ImportFromTextScreenState extends State { - final CodeController _codeController = CodeController( - language: dart, - text: "// Insert code here...", - ); + final CodeController _codeController = CodeController(language: dart, text: "// Insert code here..."); bool _isLoading = false; @override @@ -273,26 +232,20 @@ class _ImportFromTextScreenState extends State { Future _pasteFromClipboard() async { setState(() => _isLoading = true); - + try { final clipboardData = await Clipboard.getData('text/plain'); if (clipboardData?.text != null) { _codeController.text = clipboardData!.text!; } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Clipboard is empty'), - backgroundColor: Colors.orange, - ), - ); + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text('Clipboard is empty'), backgroundColor: Colors.orange)); } } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text('Error pasting from clipboard: $e'), - backgroundColor: Colors.red, - ), - ); + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('Error pasting from clipboard: $e'), backgroundColor: Colors.red)); } finally { setState(() => _isLoading = false); } @@ -302,42 +255,33 @@ class _ImportFromTextScreenState extends State { final text = _codeController.fullText; if (text.isEmpty) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Please enter or paste formula text'), - backgroundColor: Colors.orange, - ), + const SnackBar(content: Text('Please enter or paste formula text'), backgroundColor: Colors.orange), ); return; } setState(() => _isLoading = true); - + try { final importService = ImportService(); final elements = importService.parseSharedText(text); - + if (!mounted) return; - + final result = await Navigator.push( context, MaterialPageRoute( - builder: (context) => ImportPreviewScreen( - elements: elements, - corpus: widget.corpus, - ), + builder: (context) => ImportPreviewScreen(elements: elements, corpus: widget.corpus), ), ); - + if (result == true) { Navigator.pop(context, true); } } catch (e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text('Error parsing text: $e'), - backgroundColor: Colors.red, - ), - ); + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('Error parsing text: $e'), backgroundColor: Colors.red)); } finally { setState(() => _isLoading = false); } @@ -346,9 +290,7 @@ class _ImportFromTextScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('Import from Text'), - ), + appBar: AppBar(title: const Text('Import from Text')), body: Column( children: [ Expanded( @@ -356,11 +298,7 @@ class _ImportFromTextScreenState extends State { data: CodeThemeData(styles: monokaiSublimeTheme), child: Padding( padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - child: CodeField( - controller: _codeController, - ), - ), + child: SingleChildScrollView(child: CodeField(controller: _codeController)), ), ), ), @@ -372,11 +310,7 @@ class _ImportFromTextScreenState extends State { child: ElevatedButton.icon( onPressed: _isLoading ? null : _pasteFromClipboard, icon: _isLoading - ? const SizedBox( - width: 16, - height: 16, - child: CircularProgressIndicator(strokeWidth: 2), - ) + ? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2)) : const Icon(Icons.content_paste), label: const Text('Paste'), ), @@ -385,7 +319,7 @@ class _ImportFromTextScreenState extends State { Expanded( child: ElevatedButton.icon( onPressed: _isLoading ? null : _import, - icon: const Icon(Icons.import_export), + icon: const Icon(Icons.library_add), label: const Text('Import'), ), ), diff --git a/lib/main.dart b/lib/main.dart index 85a2812..16cc515 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,7 +83,7 @@ class _CorpusLoaderState extends State { title: const Text('Formulas'), actions: [ IconButton( - icon: const Icon(Icons.import_export), + icon: const Icon(Icons.library_add), tooltip: 'Import formulas', onPressed: _handleImport, ),