Changed icons and other minor changes

This commit is contained in:
Álvaro González 2026-03-19 12:05:10 +01:00
parent 12d755d810
commit daebfeb385
4 changed files with 63 additions and 167 deletions

View file

@ -81,23 +81,6 @@ class _FormulaListState extends State<FormulaList> {
}
}
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<FormulaList> {
);
}
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<FormulaList> {
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);

View file

@ -121,14 +121,13 @@ class _FormulaScreenState extends State<FormulaScreen> {
}
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<FormulaScreen> {
children: [
// Fixed width for field name
SizedBox(
width: 150,
width: 50,
child: Text(
formula.output.name,
overflow: TextOverflow.ellipsis,

View file

@ -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<FormulaElement> 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<ImportPreviewScreen> createState() => _ImportPreviewScreenState();
@ -52,9 +47,7 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
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,12 +70,9 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
}).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;
}
@ -98,12 +88,9 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
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<ImportPreviewScreen> {
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<ImportPreviewScreen> {
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)),
],
@ -189,9 +155,7 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
),
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<ImportPreviewScreen> {
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)),
],
),
),
@ -249,20 +214,14 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
class ImportFromTextScreen extends StatefulWidget {
final Corpus corpus;
const ImportFromTextScreen({
super.key,
required this.corpus,
});
const ImportFromTextScreen({super.key, required this.corpus});
@override
State<ImportFromTextScreen> createState() => _ImportFromTextScreenState();
}
class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
final CodeController _codeController = CodeController(
language: dart,
text: "// Insert code here...",
);
final CodeController _codeController = CodeController(language: dart, text: "// Insert code here...");
bool _isLoading = false;
@override
@ -279,20 +238,14 @@ class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
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,10 +255,7 @@ class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
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;
}
@ -321,10 +271,7 @@ class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImportPreviewScreen(
elements: elements,
corpus: widget.corpus,
),
builder: (context) => ImportPreviewScreen(elements: elements, corpus: widget.corpus),
),
);
@ -332,12 +279,9 @@ class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
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<ImportFromTextScreen> {
@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<ImportFromTextScreen> {
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<ImportFromTextScreen> {
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<ImportFromTextScreen> {
Expanded(
child: ElevatedButton.icon(
onPressed: _isLoading ? null : _import,
icon: const Icon(Icons.import_export),
icon: const Icon(Icons.library_add),
label: const Text('Import'),
),
),

View file

@ -83,7 +83,7 @@ class _CorpusLoaderState extends State<CorpusLoader> {
title: const Text('Formulas'),
actions: [
IconButton(
icon: const Icon(Icons.import_export),
icon: const Icon(Icons.library_add),
tooltip: 'Import formulas',
onPressed: _handleImport,
),