From 4fb89fa78bcbf34dde7d45855c456369a80abe16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Gonz=C3=A1lez?= Date: Sat, 28 Feb 2026 14:22:18 +0100 Subject: [PATCH] added shareplus --- TODO.md | 3 +-- assets/formulas/optics.d4rt | 35 +++++++++++++++++++++++++++++++++-- lib/ai/formula_list.dart | 10 ++++++---- lib/ai/formula_screen.dart | 1 + pubspec.lock | 2 +- pubspec.yaml | 1 + 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/TODO.md b/TODO.md index b09e566..92aa2ec 100644 --- a/TODO.md +++ b/TODO.md @@ -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] 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. -- [ ] -- [ ] Investigate startup time when there is no previous database and corpus is loaded from assets. +- [ ] Change Share package to share_plus, because share is deprecated. diff --git a/assets/formulas/optics.d4rt b/assets/formulas/optics.d4rt index f28a4c4..18ea977 100644 --- a/assets/formulas/optics.d4rt +++ b/assets/formulas/optics.d4rt @@ -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"] + } +]; diff --git a/lib/ai/formula_list.dart b/lib/ai/formula_list.dart index 5348710..b45f7e0 100644 --- a/lib/ai/formula_list.dart +++ b/lib/ai/formula_list.dart @@ -3,7 +3,7 @@ import 'package:flutter/services.dart'; // For Clipboard import 'package:d4rt_formulas/formula_models.dart'; import '../corpus.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 { final Corpus corpus; @@ -63,9 +63,11 @@ class _FormulaListState extends State { final exportString = '[${literals.join(', ')}]'; // Share the string - await Share.share( - exportString, - subject: 'Sharing formula: ${formula.name}', + await share_plus.SharePlus.instance.share( + share_plus.ShareParams( + text: exportString, + subject: 'Sharing formula: ${formula.name}', + ), ); } catch (e) { _showErrorDialog('Error sharing formula: $e'); diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index 7bf6dc5..4ec9f0c 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -45,6 +45,7 @@ class D4rtEditingController extends TextEditingController { FormulaResult? get d4rtValue => _lastValue; + @override set text(String newText) { super.text = newText; validate(); diff --git a/pubspec.lock b/pubspec.lock index 871f09b..d7b2023 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -505,7 +505,7 @@ packages: source: hosted version: "1.3.0" markdown: - dependency: transitive + dependency: "direct main" description: name: markdown sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1" diff --git a/pubspec.yaml b/pubspec.yaml index 9d9144a..b5a09ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: resource_portable: d4rt: ^0.2.0 analyzer: ^8.4.1 + markdown: flutter_markdown_plus: flutter_markdown_plus_latex: flutter_code_editor: