Changed icons and other minor changes
This commit is contained in:
parent
12d755d810
commit
daebfeb385
4 changed files with 63 additions and 167 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,33 +70,27 @@ 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;
|
||||
}
|
||||
|
||||
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<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)),
|
||||
],
|
||||
|
|
@ -171,7 +137,7 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
|
|||
|
||||
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<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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -222,7 +187,7 @@ class _ImportPreviewScreenState extends State<ImportPreviewScreen> {
|
|||
|
||||
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<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
|
||||
|
|
@ -273,26 +232,20 @@ class _ImportFromTextScreenState extends State<ImportFromTextScreen> {
|
|||
|
||||
Future<void> _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<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;
|
||||
}
|
||||
|
||||
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<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'),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in a new issue