dart --fix

This commit is contained in:
Álvaro González 2025-09-05 18:53:06 +02:00
parent 8fb175bcda
commit e6bd0f512f
8 changed files with 36 additions and 47 deletions

View file

@ -1,4 +1,3 @@
import 'package:d4rt_formulas/d4rt_formulas.dart' as pruebas_d4rt;
import 'package:d4rt/d4rt.dart';
void main() {

View file

@ -4,6 +4,7 @@
/// 1. Create formulas with input/output specifications
/// 2. Evaluate formulas with different input values
/// 3. Handle evaluation errors
library;
import 'package:d4rt_formulas/d4rt_formulas.dart';

View file

@ -1,40 +1,7 @@
import 'package:flutter/material.dart';
class VariableSpec {
final String name;
final String magnitude;
static final MAGNITUDELESS = "magnitudeless";
import '../formula_models.dart';
VariableSpec({required this.name, required this.magnitude});
@override
String toString() => 'var($name: $magnitude)';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is VariableSpec &&
runtimeType == other.runtimeType &&
magnitude == other.magnitude &&
name == other.name;
@override
int get hashCode => Object.hash(magnitude, name);
}
class Formula {
final String name;
final List<VariableSpec> input;
final VariableSpec output;
final String d4rtCode;
Formula({
required this.name,
required this.input,
required this.output,
required this.d4rtCode,
});
}
class FormulaWidget extends StatelessWidget {
final Formula formula;
@ -46,7 +13,7 @@ class FormulaWidget extends StatelessWidget {
final bool showCode;
const FormulaWidget({
Key? key,
super.key,
required this.formula,
this.fontSize = 16.0,
this.textColor,
@ -54,7 +21,7 @@ class FormulaWidget extends StatelessWidget {
this.padding = const EdgeInsets.all(16.0),
this.showMagnitudes = true,
this.showCode = false,
}) : super(key: key);
});
@override
Widget build(BuildContext context) {
@ -99,7 +66,7 @@ class FormulaWidget extends StatelessWidget {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
color: Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.3),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Theme.of(context).dividerColor,
@ -291,7 +258,7 @@ class FormulaWidget extends StatelessWidget {
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.5),
color: Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.5),
borderRadius: BorderRadius.circular(6),
),
child: Text(

View file

@ -2,7 +2,7 @@
///
/// This library provides data models for representing formulas and an evaluator
/// for executing them using the d4rt Dart interpreter.
library d4rt_formulas;
library;
export 'formula_models.dart';
export 'formula_evaluator.dart';

View file

@ -86,7 +86,7 @@ class Formula {
final formulas = list.map( (set) => Formula.fromSet(set as Map) );
return formulas.toList(growable: false) as List<Formula>;
return formulas.toList(growable: false);
}
factory Formula.fromSet(Map<Object?, Object?> theSet) {
@ -119,7 +119,7 @@ class Formula {
VariableSpec output = parseVar(outputSet);
String d4rtCode = theSet.get("d4rtCode");
return new Formula(
return Formula(
name: name,
input: input,
output: output,

View file

@ -1,7 +1,30 @@
import 'package:d4rt_formulas/ai/FormulaWidget.dart';
import 'package:d4rt_formulas/formula_models.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
//runApp(const MyApp());
Formula formula = sampleFormula();
runApp( MaterialApp( home: FormulaWidget(formula: formula)) );
}
Formula sampleFormula(){
final literal = """
{
"name": "Newton's second law",
"input": [
{ "name": 'm', "magnitude": 'mass'},
{ "name": 'a', "magnitude": 'acceleration'}
],
"output": { "name": 'F', "magnitude": 'force'},
"d4rtCode": '''
F = a * m;
'''
}
""";
final formula = Formula.fromStringLiteral(literal);
return formula;
}
class MyApp extends StatelessWidget {

View file

@ -37,6 +37,7 @@ dependencies:
d4rt:
flutter_d4rt:
collection: any
dev_dependencies:
flutter_test:
sdk: flutter

View file

@ -1,6 +1,4 @@
import 'dart:convert';
import 'package:d4rt/d4rt.dart';
import 'package:d4rt_formulas/formula_evaluator.dart';
import 'package:test/test.dart';
import 'package:d4rt_formulas/formula_models.dart';
@ -16,7 +14,7 @@ void main() {
],
"output": { "name": 'F', "magnitude": 'force'},
"d4rtCode": '''
return a * m;
F = a * m;
'''
};
@ -41,7 +39,7 @@ void main() {
],
"output": { "name": 'F', "magnitude": 'force'},
"d4rtCode": '''
return a * m;
F = a * m;
'''
}
""";