Better error handling of strings
This commit is contained in:
parent
9f2c569279
commit
42d775ff5b
4 changed files with 47 additions and 15 deletions
12
Makefile
12
Makefile
|
|
@ -17,25 +17,25 @@ clean-container: build-container
|
|||
pub-get-container: build-container
|
||||
./flutterw pub get
|
||||
|
||||
test: pub-get-container
|
||||
test:
|
||||
./flutterw test
|
||||
|
||||
build-builders: build-container
|
||||
./flutterw pub run build_runner build --delete-conflicting-outputs
|
||||
|
||||
build-android-release-container: pub-get-container
|
||||
build-android-release-container:
|
||||
./flutterw build apk --release
|
||||
|
||||
build-linux-debug-container: pub-get-container
|
||||
build-linux-debug-container:
|
||||
./flutterw build linux --debug
|
||||
|
||||
build-web-debug-container: pub-get-container
|
||||
build-web-debug-container:
|
||||
./flutterw build web --debug
|
||||
|
||||
run-linux-debug-container: pub-get-container
|
||||
run-linux-debug-container:
|
||||
./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
|
||||
|
||||
run-linux-debug-native:
|
||||
|
|
|
|||
2
TODO.md
2
TODO.md
|
|
@ -47,3 +47,5 @@
|
|||
- [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] 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
|
||||
|
|
|
|||
|
|
@ -32,13 +32,14 @@ RUN chown -R $USER_ID:$GROUP_ID /sdks/flutter
|
|||
USER $USER_ID:$GROUP_ID
|
||||
|
||||
# Pre-cache Flutter artifacts for Linux, Android, and Web to speed up subsequent builds
|
||||
#WORKDIR /dummy_app_only_for_cache
|
||||
#RUN flutter create . && flutter pub get
|
||||
#RUN flutter precache --linux
|
||||
#RUN flutter build linux
|
||||
#RUN flutter precache --web
|
||||
#RUN flutter build web
|
||||
WORKDIR /dummy_app_only_for_cache
|
||||
RUN flutter create . && flutter pub get
|
||||
RUN flutter precache --linux
|
||||
RUN flutter precache --web
|
||||
#RUN flutter precache --android
|
||||
|
||||
#RUN flutter build linux
|
||||
#RUN flutter build web
|
||||
#RUN flutter build apk
|
||||
|
||||
WORKDIR /app
|
||||
|
|
|
|||
|
|
@ -25,10 +25,25 @@ class D4rtEditingController extends TextEditingController {
|
|||
String? _lastError;
|
||||
String? get lastError => _lastError;
|
||||
FormulaResult? _lastValue;
|
||||
final bool isString;
|
||||
|
||||
D4rtEditingController({super.text});
|
||||
D4rtEditingController({super.text, this.isString = false});
|
||||
|
||||
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 {
|
||||
_lastValue = null;
|
||||
if( text.trim().isEmpty ){
|
||||
|
|
@ -38,12 +53,26 @@ class D4rtEditingController extends TextEditingController {
|
|||
_lastError = null;
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
errorHandler.notify(e, s);
|
||||
//errorHandler.notify(e, s);
|
||||
_lastError = e.toString();
|
||||
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;
|
||||
|
||||
set text(String newText) {
|
||||
|
|
@ -79,7 +108,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
|||
_selectedValues[input.name] = input.values!.first;
|
||||
} else {
|
||||
// numeric variable -> use D4rtEditingController
|
||||
_inputControllers[input.name] = D4rtEditingController();
|
||||
_inputControllers[input.name] = D4rtEditingController(isString: input.unit == "string");
|
||||
_inputControllers[input.name]!.addListener(_evaluateFormula);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue