added shareplus

This commit is contained in:
Álvaro González 2026-02-28 14:22:18 +01:00
parent 9b6887f58a
commit 4fb89fa78b
6 changed files with 43 additions and 9 deletions

View file

@ -32,5 +32,4 @@
- [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies(). - [X] Add a Share button to the formula list. It will export the array string literal of the formula with the units from Corpus.withDependencies().
- [X] Replace flutter-markdown with flutter-markdown-plus - [X] Replace flutter-markdown with flutter-markdown-plus
- [X] Heron's formula: investigate why a=3, b=40, c=5 yields NaN. Root cause: input values don't form a valid triangle (violate triangle inequality: 3+5=8 is not > 40). Added documentation note to the formula description. - [X] Heron's formula: investigate why a=3, b=40, c=5 yields NaN. Root cause: input values don't form a valid triangle (violate triangle inequality: 3+5=8 is not > 40). Added documentation note to the formula description.
- [ ] - [ ] Change Share package to share_plus, because share is deprecated.
- [ ] Investigate startup time when there is no previous database and corpus is loaded from assets.

View file

@ -1,4 +1,35 @@
[ [
{"name":"Snell's Law","input":[{"name":"n1","unit":"scalar"},{"name":"n2","unit":"scalar"},{"name":"theta1","unit":"degree"}],"output":{"name":"theta2","unit":"degree"},"d4rtCode":"var theta1Rad = theta1 * (pi / 180); var sinTheta2 = (n1 * sin(theta1Rad)) / n2; theta2 = asin(sinTheta2) * (180 / pi);","tags":["physics","optics","light"]} {
] "name": "Snell's Law",
"description": r'''
Refraction of light when passing through different media
$$n_1 \sin(\theta_1) = n_2 \sin(\theta_2)$$
Where:
- $n_1$: Refractive index of the first medium
- $n_2$: Refractive index of the second medium
- $\theta_1$: Angle of incidence (degrees)
- $\theta_2$: Angle of refraction (degrees)
![Figure](https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Snells_law_Diagram_B_vector.svg/330px-Snells_law_Diagram_B_vector.svg.png)
Snell's Law describes how light bends when traveling between media with different refractive indices.
The product of refractive index and sine of angle remains constant across the interface.
''',
"input": [
{"name": "n1", "unit": "scalar"},
{"name": "n2", "unit": "scalar"},
{"name": "theta1", "unit": "degree"}
],
"output": {"name": "theta2", "unit": "degree"},
"d4rtCode": r"""
var theta1Rad = theta1 * (pi / 180);
var sinTheta2 = (n1 * sin(theta1Rad)) / n2;
theta2 = asin(sinTheta2) * (180 / pi);
""",
"tags": ["physics", "optics", "light"]
}
];

View file

@ -3,7 +3,7 @@ import 'package:flutter/services.dart'; // For Clipboard
import 'package:d4rt_formulas/formula_models.dart'; import 'package:d4rt_formulas/formula_models.dart';
import '../corpus.dart'; import '../corpus.dart';
import 'formula_screen.dart'; import 'formula_screen.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart' as share_plus;
class FormulaList extends StatefulWidget { class FormulaList extends StatefulWidget {
final Corpus corpus; final Corpus corpus;
@ -63,9 +63,11 @@ class _FormulaListState extends State<FormulaList> {
final exportString = '[${literals.join(', ')}]'; final exportString = '[${literals.join(', ')}]';
// Share the string // Share the string
await Share.share( await share_plus.SharePlus.instance.share(
exportString, share_plus.ShareParams(
text: exportString,
subject: 'Sharing formula: ${formula.name}', subject: 'Sharing formula: ${formula.name}',
),
); );
} catch (e) { } catch (e) {
_showErrorDialog('Error sharing formula: $e'); _showErrorDialog('Error sharing formula: $e');

View file

@ -45,6 +45,7 @@ class D4rtEditingController extends TextEditingController {
FormulaResult? get d4rtValue => _lastValue; FormulaResult? get d4rtValue => _lastValue;
@override
set text(String newText) { set text(String newText) {
super.text = newText; super.text = newText;
validate(); validate();

View file

@ -505,7 +505,7 @@ packages:
source: hosted source: hosted
version: "1.3.0" version: "1.3.0"
markdown: markdown:
dependency: transitive dependency: "direct main"
description: description:
name: markdown name: markdown
sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1" sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1"

View file

@ -37,6 +37,7 @@ dependencies:
resource_portable: resource_portable:
d4rt: ^0.2.0 d4rt: ^0.2.0
analyzer: ^8.4.1 analyzer: ^8.4.1
markdown:
flutter_markdown_plus: flutter_markdown_plus:
flutter_markdown_plus_latex: flutter_markdown_plus_latex:
flutter_code_editor: flutter_code_editor: