Better error handling of strings

This commit is contained in:
alvaro@a33 2026-02-27 11:29:15 +01:00
parent 9f2c569279
commit 42d775ff5b
4 changed files with 47 additions and 15 deletions

View file

@ -17,25 +17,25 @@ clean-container: build-container
pub-get-container: build-container pub-get-container: build-container
./flutterw pub get ./flutterw pub get
test: pub-get-container test:
./flutterw test ./flutterw test
build-builders: build-container build-builders: build-container
./flutterw pub run build_runner build --delete-conflicting-outputs ./flutterw pub run build_runner build --delete-conflicting-outputs
build-android-release-container: pub-get-container build-android-release-container:
./flutterw build apk --release ./flutterw build apk --release
build-linux-debug-container: pub-get-container build-linux-debug-container:
./flutterw build linux --debug ./flutterw build linux --debug
build-web-debug-container: pub-get-container build-web-debug-container:
./flutterw build web --debug ./flutterw build web --debug
run-linux-debug-container: pub-get-container run-linux-debug-container:
./flutterw run -d linux ./flutterw run -d linux
run-web-debug-container: pub-get-container run-web-debug-container:
./flutterw run --web-port $${WEB_PORT:-8081} -d web-server ./flutterw run --web-port $${WEB_PORT:-8081} -d web-server
run-linux-debug-native: run-linux-debug-native:

View file

@ -47,3 +47,5 @@
- [R] There is one row for the ouput variable, similar to the row for the input variable - [R] There is one row for the ouput variable, similar to the row for the input variable
- [R] d4rtCode is a text area with dart syntax highligthing - [R] d4rtCode is a text area with dart syntax highligthing
- [R] At the botton, a button allows to test the edited Formula, launching a FormulaScreen - [R] At the botton, a button allows to test the edited Formula, launching a FormulaScreen
- [ ] When _FormulaScreenState._evaluateFormula() detect an error, instead of show an SnackBar, show a ExpansionTile with "⚠️ There were an error. Show details..." with the details of the exception. The ExpansionTile will be invisible if there is no error.
- [ ] Investigate https://pub.dev/packages/quantity

View file

@ -32,13 +32,14 @@ RUN chown -R $USER_ID:$GROUP_ID /sdks/flutter
USER $USER_ID:$GROUP_ID USER $USER_ID:$GROUP_ID
# Pre-cache Flutter artifacts for Linux, Android, and Web to speed up subsequent builds # Pre-cache Flutter artifacts for Linux, Android, and Web to speed up subsequent builds
#WORKDIR /dummy_app_only_for_cache WORKDIR /dummy_app_only_for_cache
#RUN flutter create . && flutter pub get RUN flutter create . && flutter pub get
#RUN flutter precache --linux RUN flutter precache --linux
#RUN flutter build linux RUN flutter precache --web
#RUN flutter precache --web
#RUN flutter build web
#RUN flutter precache --android #RUN flutter precache --android
#RUN flutter build linux
#RUN flutter build web
#RUN flutter build apk #RUN flutter build apk
WORKDIR /app WORKDIR /app

View file

@ -25,10 +25,25 @@ class D4rtEditingController extends TextEditingController {
String? _lastError; String? _lastError;
String? get lastError => _lastError; String? get lastError => _lastError;
FormulaResult? _lastValue; FormulaResult? _lastValue;
final bool isString;
D4rtEditingController({super.text}); D4rtEditingController({super.text, this.isString = false});
bool validate() { bool validate() {
if( _validateAsNumberExpression(text) ){
return true;
}
if( isString && _validateAsStringExpression(text) ){
return true;
}
return false;
}
bool _validateAsNumberExpression(String text){
return _validateAsD4rtExpression(text) && _lastValue is NumberResult;
}
bool _validateAsD4rtExpression(String text){
try { try {
_lastValue = null; _lastValue = null;
if( text.trim().isEmpty ){ if( text.trim().isEmpty ){
@ -38,12 +53,26 @@ class D4rtEditingController extends TextEditingController {
_lastError = null; _lastError = null;
return true; return true;
} catch (e, s) { } catch (e, s) {
errorHandler.notify(e, s); //errorHandler.notify(e, s);
_lastError = e.toString(); _lastError = e.toString();
return false; return false;
} }
} }
bool _validateAsStringExpression(String text){
if( _validateAsD4rtExpression(text) && _lastValue is StringResult ){
return true;
}
if( _validateAsD4rtExpression('"' + text + '"') && _lastValue is StringResult ){
return true;
}
if( _validateAsD4rtExpression("'" + text + "'") && _lastValue is StringResult ){
return true;
}
return false;
}
FormulaResult? get d4rtValue => _lastValue; FormulaResult? get d4rtValue => _lastValue;
set text(String newText) { set text(String newText) {
@ -79,7 +108,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
_selectedValues[input.name] = input.values!.first; _selectedValues[input.name] = input.values!.first;
} else { } else {
// numeric variable -> use D4rtEditingController // numeric variable -> use D4rtEditingController
_inputControllers[input.name] = D4rtEditingController(); _inputControllers[input.name] = D4rtEditingController(isString: input.unit == "string");
_inputControllers[input.name]!.addListener(_evaluateFormula); _inputControllers[input.name]!.addListener(_evaluateFormula);
} }
} }