dart --fix
This commit is contained in:
parent
8fb175bcda
commit
e6bd0f512f
8 changed files with 36 additions and 47 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:d4rt_formulas/d4rt_formulas.dart' as pruebas_d4rt;
|
|
||||||
import 'package:d4rt/d4rt.dart';
|
import 'package:d4rt/d4rt.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
/// 1. Create formulas with input/output specifications
|
/// 1. Create formulas with input/output specifications
|
||||||
/// 2. Evaluate formulas with different input values
|
/// 2. Evaluate formulas with different input values
|
||||||
/// 3. Handle evaluation errors
|
/// 3. Handle evaluation errors
|
||||||
|
library;
|
||||||
|
|
||||||
import 'package:d4rt_formulas/d4rt_formulas.dart';
|
import 'package:d4rt_formulas/d4rt_formulas.dart';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class VariableSpec {
|
import '../formula_models.dart';
|
||||||
final String name;
|
|
||||||
final String magnitude;
|
|
||||||
static final MAGNITUDELESS = "magnitudeless";
|
|
||||||
|
|
||||||
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 {
|
class FormulaWidget extends StatelessWidget {
|
||||||
final Formula formula;
|
final Formula formula;
|
||||||
|
|
@ -46,7 +13,7 @@ class FormulaWidget extends StatelessWidget {
|
||||||
final bool showCode;
|
final bool showCode;
|
||||||
|
|
||||||
const FormulaWidget({
|
const FormulaWidget({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.formula,
|
required this.formula,
|
||||||
this.fontSize = 16.0,
|
this.fontSize = 16.0,
|
||||||
this.textColor,
|
this.textColor,
|
||||||
|
|
@ -54,7 +21,7 @@ class FormulaWidget extends StatelessWidget {
|
||||||
this.padding = const EdgeInsets.all(16.0),
|
this.padding = const EdgeInsets.all(16.0),
|
||||||
this.showMagnitudes = true,
|
this.showMagnitudes = true,
|
||||||
this.showCode = false,
|
this.showCode = false,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -99,7 +66,7 @@ class FormulaWidget extends StatelessWidget {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
|
color: Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.3),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: Theme.of(context).dividerColor,
|
color: Theme.of(context).dividerColor,
|
||||||
|
|
@ -291,7 +258,7 @@ class FormulaWidget extends StatelessWidget {
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.5),
|
color: Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.5),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
///
|
///
|
||||||
/// This library provides data models for representing formulas and an evaluator
|
/// This library provides data models for representing formulas and an evaluator
|
||||||
/// for executing them using the d4rt Dart interpreter.
|
/// for executing them using the d4rt Dart interpreter.
|
||||||
library d4rt_formulas;
|
library;
|
||||||
|
|
||||||
export 'formula_models.dart';
|
export 'formula_models.dart';
|
||||||
export 'formula_evaluator.dart';
|
export 'formula_evaluator.dart';
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class Formula {
|
||||||
|
|
||||||
final formulas = list.map( (set) => Formula.fromSet(set as Map) );
|
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) {
|
factory Formula.fromSet(Map<Object?, Object?> theSet) {
|
||||||
|
|
@ -119,7 +119,7 @@ class Formula {
|
||||||
VariableSpec output = parseVar(outputSet);
|
VariableSpec output = parseVar(outputSet);
|
||||||
String d4rtCode = theSet.get("d4rtCode");
|
String d4rtCode = theSet.get("d4rtCode");
|
||||||
|
|
||||||
return new Formula(
|
return Formula(
|
||||||
name: name,
|
name: name,
|
||||||
input: input,
|
input: input,
|
||||||
output: output,
|
output: output,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,30 @@
|
||||||
|
import 'package:d4rt_formulas/ai/FormulaWidget.dart';
|
||||||
|
import 'package:d4rt_formulas/formula_models.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
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 {
|
class MyApp extends StatelessWidget {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ dependencies:
|
||||||
d4rt:
|
d4rt:
|
||||||
flutter_d4rt:
|
flutter_d4rt:
|
||||||
|
|
||||||
|
collection: any
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:d4rt/d4rt.dart';
|
|
||||||
import 'package:d4rt_formulas/formula_evaluator.dart';
|
import 'package:d4rt_formulas/formula_evaluator.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:d4rt_formulas/formula_models.dart';
|
import 'package:d4rt_formulas/formula_models.dart';
|
||||||
|
|
@ -16,7 +14,7 @@ void main() {
|
||||||
],
|
],
|
||||||
"output": { "name": 'F', "magnitude": 'force'},
|
"output": { "name": 'F', "magnitude": 'force'},
|
||||||
"d4rtCode": '''
|
"d4rtCode": '''
|
||||||
return a * m;
|
F = a * m;
|
||||||
'''
|
'''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,7 +39,7 @@ void main() {
|
||||||
],
|
],
|
||||||
"output": { "name": 'F', "magnitude": 'force'},
|
"output": { "name": 'F', "magnitude": 'force'},
|
||||||
"d4rtCode": '''
|
"d4rtCode": '''
|
||||||
return a * m;
|
F = a * m;
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue