Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result updrade #71

Merged
merged 8 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
# - uses: subosito/flutter-action@v2
with:
channel: 'stable'
version: 3.10.1
version: 3.16.5
# - run: |
# sudo apt-get update -y
# sudo apt-get install -y ninja-build libgtk-3-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# - uses: subosito/flutter-action@v2
with:
channel: 'stable'
version: 3.3.10
version: 3.16.5
# - run: |
# sudo apt-get update -y
# sudo apt-get install -y ninja-build libgtk-3-dev
Expand Down
7 changes: 5 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 1.0.0+1
publish_to: 'none'

environment:
sdk: '>=2.18.2 <3.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
Expand All @@ -20,7 +20,10 @@ dependencies:
git:
url: https://github.com/a-givertzman/hmi_networking.git
ref: master
fl_chart: ^0.55.1
fl_chart:
git:
url: https://github.com/a-givertzman/fl_chart.git
ref: master
another_flushbar: ^1.12.29

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _ControlButtonIndicatorState extends State<ControlButtonIndicator> with Ti
child: Text(
_stateText,
style: stateTextStyle.apply(color: color),
textScaleFactor: _stateTextScaleFactor,
textScaler: TextScaler.linear(_stateTextScaleFactor),
),
),
],
Expand Down
7 changes: 4 additions & 3 deletions lib/src/core/overflowable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OverflowableText extends StatelessWidget {
/// the specified font size.
///
/// The value given to the constructor as textScaleFactor. If null, will
/// use the [MediaQueryData.textScaleFactor] obtained from the ambient
/// use the [MediaQueryData.textScaler] obtained from the ambient
/// [MediaQuery], or 1.0 if there is no [MediaQuery] in scope.
final double? textScaleFactor;

Expand Down Expand Up @@ -153,6 +153,7 @@ class OverflowableText extends StatelessWidget {
@override
Widget build(BuildContext context) {
final textData = data;
final textScaler = textScaleFactor != null ? TextScaler.linear(textScaleFactor!) : null;
if (textData != null) {
return Text(
textData,
Expand All @@ -163,7 +164,7 @@ class OverflowableText extends StatelessWidget {
locale: locale,
softWrap: softWrap,
overflow: overflow,
textScaleFactor: textScaleFactor,
textScaler: textScaler,
maxLines: maxLines,
semanticsLabel: semanticsLabel,
textWidthBasis: textWidthBasis,
Expand All @@ -180,7 +181,7 @@ class OverflowableText extends StatelessWidget {
locale: locale,
softWrap: softWrap,
overflow: overflow,
textScaleFactor: textScaleFactor,
textScaler: textScaler,
maxLines: maxLines,
semanticsLabel: semanticsLabel,
textWidthBasis: textWidthBasis,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/core/validation/cases/max_length_validation_case.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hmi_core/hmi_core_result.dart';
import 'package:hmi_core/hmi_core_result_new.dart';

Check notice on line 1 in lib/src/core/validation/cases/max_length_validation_case.dart

View workflow job for this annotation

GitHub Actions / coverage

Good coverage level

100.00%
import 'package:hmi_core/hmi_core_failure.dart';
import 'validation_case.dart';
///
Expand All @@ -10,12 +10,12 @@
_maxLength = maxLength;
//
@override
Result<void> isSatisfiedBy(String? value) {
ResultF<void> isSatisfiedBy(String? value) {
if (value != null && value.length <= _maxLength) {
return Result(data: true);
return Ok(true);
}
return Result(
error: Failure(
return Err(
Failure(
message: 'Too many characters',
stackTrace: StackTrace.current,
),
Expand Down
10 changes: 5 additions & 5 deletions lib/src/core/validation/cases/min_length_validation_case.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hmi_core/hmi_core_result.dart';
import 'package:hmi_core/hmi_core_result_new.dart';

Check notice on line 1 in lib/src/core/validation/cases/min_length_validation_case.dart

View workflow job for this annotation

GitHub Actions / coverage

Good coverage level

100.00%
import 'package:hmi_core/hmi_core_failure.dart';
import 'validation_case.dart';
///
Expand All @@ -10,12 +10,12 @@
_minLength = minLength;
//
@override
Result<void> isSatisfiedBy(String? value) {
ResultF<void> isSatisfiedBy(String? value) {
if (value != null && value.length >= _minLength) {
return Result(data: true);
return Ok(true);
}
return Result(
error: Failure(
return Err(
Failure(
message: 'Too few characters',
stackTrace: StackTrace.current,
),
Expand Down
10 changes: 5 additions & 5 deletions lib/src/core/validation/cases/only_digits_validation_case.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hmi_core/hmi_core_result.dart';
import 'package:hmi_core/hmi_core_result_new.dart';

Check notice on line 1 in lib/src/core/validation/cases/only_digits_validation_case.dart

View workflow job for this annotation

GitHub Actions / coverage

Good coverage level

100.00%
import 'package:hmi_core/hmi_core_failure.dart';
import 'package:hmi_widgets/src/core/validation/cases/validation_case.dart';
///
Expand All @@ -7,16 +7,16 @@
const OnlyDigitsValidationCase();
//
@override
Result<void> isSatisfiedBy(String? value) {
ResultF<void> isSatisfiedBy(String? value) {
if(value != null && value.isNotEmpty) {
final regex = RegExp(r'[\d]*');
final match = regex.matchAsPrefix(value);
if (match?.end == value.length) {
return Result(data: true);
return Ok(true);
}
}
return Result(
error: Failure(
return Err(
Failure(
message: 'Only digits expected',
stackTrace: StackTrace.current,
),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/validation/cases/validation_case.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:hmi_core/hmi_core_result.dart';
import 'package:hmi_core/hmi_core_result_new.dart';
///
abstract class ValidationCase {
///
Result<void> isSatisfiedBy(String? value);
ResultF<void> isSatisfiedBy(String? value);
}
5 changes: 3 additions & 2 deletions lib/src/core/validation/validator.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'cases/validation_case.dart';

Check notice on line 1 in lib/src/core/validation/validator.dart

View workflow job for this annotation

GitHub Actions / coverage

Good coverage level

100.00%
import 'package:hmi_core/hmi_core_result_new.dart';

///
class Validator {
Expand All @@ -12,8 +13,8 @@
String? editFieldValidator(String? value) {
for (final validationCase in _cases) {
final result = validationCase.isSatisfiedBy(value);
if (result.hasError) {
return result.error.message;
if (result case Err(:final error)) {
return error.message;
}
}
return null;
Expand Down
68 changes: 38 additions & 30 deletions lib/src/edit_field/netword_edit_field/network_edit_field.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:hmi_networking/hmi_networking.dart';
import 'package:flutter/material.dart';
import 'package:hmi_core/hmi_core.dart';
import 'package:hmi_core/hmi_core_result_new.dart';
import 'package:hmi_widgets/src/edit_field/show_unauthorized_editing_flushbar.dart';

///
Expand Down Expand Up @@ -253,58 +254,62 @@ class _NetworkEditFieldState<T> extends State<NetworkEditField<T>> {
/// validating if the value can be parsed in to T (int / double)
String? _valueValidator(value) {
final result = _parseValue(value, fractionDigits: _fractionDigits);
return result.hasError ? const Localized('Invalid date value').v : null;
return switch(result) {
Ok() => null,
Err() => const Localized('Invalid date value').v,
};
}
///
void _onEditingComplete() {
_log.debug('[._onEditingComplete]');
_parseValue(_editingController.text, fractionDigits: _fractionDigits).fold(
onData: (numValue) {
if ('${numValue}' != _initValue) {
_log.debug('[.build._onEditingComplete] new numValue: ${numValue}\t_initValue: $_initValue');
_sendValue(_dsClient, _writeTagName, _responseTagName, numValue);
switch(_parseValue(_editingController.text, fractionDigits: _fractionDigits)) {
case Ok(:final value):
if ('${value}' != _initValue) {
_log.debug('[.build._onEditingComplete] new numValue: ${value}\t_initValue: $_initValue');
_sendValue(_dsClient, _writeTagName, _responseTagName, value);
}
},
onError: (failure) {
_log.debug('[.build._onEditingComplete] error: ${failure.message}');
},
);
break;
case Err(:final error):
_log.debug('[.build._onEditingComplete] error: ${error.message}');
break;
}
}
///
/// Parses string into T (int / double)
Result<T> _parseValue(String value, {int fractionDigits = 0}) {
ResultF<T> _parseValue(String value, {int fractionDigits = 0}) {
if (T == int) {
return _textToInt(value);
} else if (T == double) {
return _textToFixedDouble(value, fractionDigits);
} else {
return Result<T>(
error: Failure.convertion(
return Err(
Failure.convertion(
message: 'Ошибка в методе $runtimeType._textToFixedDouble: value "${_editingController.text}" can`t be converted',
stackTrace: StackTrace.current
),
);
}
}
///
Result<T> _textToInt(String value) {
ResultF<T> _textToInt(String value) {
final intValue = int.tryParse(value);
return intValue != null
? Result<T>(data: intValue as T)
: Result<T>(
error: Failure.convertion(
message: 'Ошибка в методе $runtimeType._textToInt: value "$value" can`t be converted into int',
stackTrace: StackTrace.current),
? Ok(intValue as T)
: Err(
Failure.convertion(
message: 'Ошибка в методе $runtimeType._textToInt: value "$value" can`t be converted into int',
stackTrace: StackTrace.current,
),
);
}
///
Result<T> _textToFixedDouble(String value, int fractionDigits) {
ResultF<T> _textToFixedDouble(String value, int fractionDigits) {
final doubleValue = double.tryParse(value);
if (doubleValue != null) {
return Result<T>(data: double.parse(doubleValue.toStringAsFixed(fractionDigits)) as T);
return Ok(double.parse(doubleValue.toStringAsFixed(fractionDigits)) as T);
} else {
return Result<T>(
error: Failure.convertion(
return Err(
Failure.convertion(
message: 'Ошибка в методе $runtimeType._textToFixedDouble: value "$value" can`t be converted into double',
stackTrace: StackTrace.current,
),
Expand All @@ -331,12 +336,15 @@ class _NetworkEditFieldState<T> extends State<NetworkEditField<T>> {
responseTimeout: _responseTimeout,
).exec(value).then((responseValue) {
setState(() {
if (responseValue.hasError) {
_savingState = OperationState.undefined;
_editingState = EditingState.changed;
} else {
_savingState = OperationState.success;
_editingState = EditingState.notChanged;
switch (responseValue) {
case Ok(value: _):
_savingState = OperationState.success;
_editingState = EditingState.notChanged;
break;
case Err(error: _):
_savingState = OperationState.undefined;
_editingState = EditingState.changed;
break;
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:core';
import 'package:hmi_networking/hmi_networking.dart';
import 'package:flutter/material.dart';
import 'package:hmi_core/hmi_core.dart';
import 'package:hmi_core/hmi_core_result_new.dart';
import 'package:hmi_widgets/src/edit_field/show_unauthorized_editing_flushbar.dart';
import 'package:hmi_widgets/src/theme/app_theme.dart';
import 'oil_data.dart';
Expand Down Expand Up @@ -193,7 +194,7 @@ class _NetworkDropdownFormFieldState extends State<NetworkDropdownFormField> {
if (mounted) {
setState(() {
_state.setSaved();
if (responseValue.hasError) {
if (responseValue case Err(error: final _)) {
_state.setChanged();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CircularValueIndicator extends StatelessWidget {
style: textStyle.copyWith(
color: textStyle.color!.withOpacity(0.7),
),
textScaleFactor: 0.8 * 0.0168 * _size,
textScaler: TextScaler.linear(0.8 * 0.0168 * _size),
),
);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ class CircularValueIndicator extends StatelessWidget {
: textStyle,
child: Text(valueText,
textAlign: TextAlign.center,
textScaleFactor: 1.5 * 0.01618 * _size,
textScaler: TextScaler.linear(1.5 * 0.01618 * _size),
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/indicators/value_indicators/text_value_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _TextValueIndicatorState extends State<TextValueIndicator> {
Text(
value.toStringAsFixed(_fractionDigits),
style: _textStyle.apply(color: color),
textScaleFactor: 1.5,
textScaler: TextScaler.linear(1.5),
),
..._buildUnitText(_valueUnit, color),
],
Expand All @@ -125,7 +125,7 @@ class _TextValueIndicatorState extends State<TextValueIndicator> {
Text(
_valueUnit,
style: _unitTextStyle.apply(color: color),
textScaleFactor: 1.5,
textScaler: TextScaler.linear(1.5),
),
];
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.0.1
homepage: https://github.com/a-givertzman/hmi_widgets

environment:
sdk: '>=2.18.2 <3.0.0'
sdk: '>=3.0.0 <4.0.0'
flutter: ">=1.17.0"

dependencies:
Expand All @@ -20,7 +20,7 @@ dev_dependencies:
# flutter_lints: ^2.0.0
fl_chart:
git:
url: https://github.com/a-givertzman/fl_chart
url: https://github.com/a-givertzman/fl_chart.git
ref: master
hmi_core:
git:
Expand Down
Loading
Loading