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,8 +53,7 @@ class _FormulaListState extends State<FormulaList> {
}).toList();
}
void _shareFormula(Formula formula) async {
try {
String _formulaAndDependenciesToStringLiteral(Formula formula) {
// Get the formula and its dependencies
final dependencies = widget.corpus.withDependencies(formula);
@ -62,7 +61,12 @@ class _FormulaListState extends State<FormulaList> {
final literals = dependencies.map((element) => element.toStringLiteral()).toList();
// Create an array string literal containing all the elements
final exportString = '[${literals.join(', ')}]';
return '[${literals.join(', ')}]';
}
void _shareFormula(Formula formula) async {
try {
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));