refactor shared formula

This commit is contained in:
Álvaro González 2026-03-01 10:49:46 +01:00
parent 1ae1f9b6d7
commit 23d8957377
2 changed files with 14 additions and 17 deletions

View file

@ -53,16 +53,20 @@ class _FormulaListState extends State<FormulaList> {
}).toList();
}
String _formulaAndDependenciesToStringLiteral(Formula formula) {
// Get the formula and its dependencies
final dependencies = widget.corpus.withDependencies(formula);
// Convert each dependency to its string literal representation
final literals = dependencies.map((element) => element.toStringLiteral()).toList();
// Create an array string literal containing all the elements
return '[${literals.join(', ')}]';
}
void _shareFormula(Formula formula) async {
try {
// Get the formula and its dependencies
final dependencies = widget.corpus.withDependencies(formula);
// Convert each dependency to its string literal representation
final literals = dependencies.map((element) => element.toStringLiteral()).toList();
// Create an array string literal containing all the elements
final exportString = '[${literals.join(', ')}]';
final exportString = _formulaAndDependenciesToStringLiteral(formula);
// Share the string
await share_plus.SharePlus.instance.share(
@ -90,14 +94,7 @@ class _FormulaListState extends State<FormulaList> {
void _copyFormula(Formula formula) async {
try {
// Get the formula and its dependencies
final dependencies = widget.corpus.withDependencies(formula);
// Convert each dependency to its string literal representation
final literals = dependencies.map((element) => element.toStringLiteral()).toList();
// Create an array string literal containing all the elements
final exportString = '[${literals.join(', ')}]';
final exportString = _formulaAndDependenciesToStringLiteral(formula);
// Copy to clipboard
await Clipboard.setData(ClipboardData(text: exportString));

View file

@ -358,7 +358,7 @@ class Formula implements FormulaElement {
buffer.write(', "input": [${inputStrings.join(", ")}]');
buffer.write(', "output": ${output.toStringLiteral()}');
buffer.write(', "d4rtCode": r"""$d4rtCode"""');
if (tags.isNotEmpty) {