WEB_PORT, para juntar en master

This commit is contained in:
Álvaro González 2026-02-01 16:16:04 +01:00
parent 1a076dff6c
commit 9ea3b88684
3 changed files with 16 additions and 4 deletions

View file

@ -23,10 +23,10 @@ run-linux-debug-container: pub-get-container
./docker-exec.sh exec flutter run -d linux ./docker-exec.sh exec flutter run -d linux
run-web-debug-container: pub-get-container run-web-debug-container: pub-get-container
./docker-exec.sh exec flutter run --web-port 8081 -d web-server ./docker-exec.sh exec flutter run --web-port $${WEB_PORT:-8081} -d web-server
run-linux-debug-native: build-linux-debug-container run-linux-debug-native: build-linux-debug-container
./build/linux/x64/debug/bundle/d4rt_formulas ./build/linux/x64/debug/bundle/d4rt_formulas
run-web-debug-native: build-web-debug-container run-web-debug-native: build-web-debug-container
cd build/web && python3 -m http.server 8081 cd build/web && python3 -m http.server $${WEB_PORT:-8081}

View file

@ -142,6 +142,8 @@ class FormulaEvaluator {
import "package:d4rt_formulas.dart"; import "package:d4rt_formulas.dart";
"""; """;
static const reservedVariableNames = { "variableValues", "indexOf", "variableAllowedValues"} ;
String _buildCompleteSource(Formula formula, Map<String, dynamic> inputValues) { String _buildCompleteSource(Formula formula, Map<String, dynamic> inputValues) {
final buffer = StringBuffer(); final buffer = StringBuffer();
@ -220,10 +222,12 @@ class FormulaEvaluator {
// Some functions to deal with string values // Some functions to deal with string values
buffer.writeln(""" buffer.writeln("""
int indexOf(String inputName) { // If return type is int, there is an error converting double to int 🤷
dynamic indexOf(String inputName) {
String value = variableValues[inputName]; String value = variableValues[inputName];
String allowedValues = variableAllowedValues[inputName]; String allowedValues = variableAllowedValues[inputName];
return allowedValues.indexOf(value); dynamic ret = allowedValues.indexOf(value) as int;
return ret as int;
} }
"""); """);

View file

@ -1,5 +1,6 @@
import 'package:d4rt/d4rt.dart'; import 'package:d4rt/d4rt.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:d4rt_formulas/d4rt_formulas.dart';
abstract class SetUtils { abstract class SetUtils {
static Object safeGet(Map<Object?, Object?> map, String key) { static Object safeGet(Map<Object?, Object?> map, String key) {
@ -105,6 +106,13 @@ class VariableSpec {
final List<dynamic>? values; final List<dynamic>? values;
VariableSpec({required this.name, this.unit, this.values}){ VariableSpec({required this.name, this.unit, this.values}){
validate();
}
void validate(){
if( FormulaEvaluator.reservedVariableNames.contains(name) ){
throw ArgumentError("$name: is a reserved variable name for FormulaEvaluator");
}
final valuesValid = values != null && values?.isNotEmpty == true; final valuesValid = values != null && values?.isNotEmpty == true;
if( unit == null && !valuesValid ){ if( unit == null && !valuesValid ){
throw ArgumentError("$name: at least unit or allowedValues should be valid"); throw ArgumentError("$name: at least unit or allowedValues should be valid");