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

Added min value for SmallLinearValueIndicator #68

Merged
merged 4 commits into from
Jun 20, 2023
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
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import 'package:flutter/material.dart';
import 'package:hmi_widgets/hmi_widgets.dart';
///
class PointerProgressIndicator extends StatelessWidget {
final double _value;
final double _minHeight;
final double _pointerThickness;
final double _scaleLineThickness;
final Color? _color;
///
const PointerProgressIndicator({
super.key,
double value = 0,
required double minHeight,
double value = 0,
Color? color,
double pointerThickness = 4,
double scaleLineThickness = 0.25,
}) :
_value = value,
_value = value,
_color = color,
_minHeight = minHeight,
_pointerThickness = pointerThickness,
_scaleLineThickness = scaleLineThickness;
Expand All @@ -23,8 +25,7 @@ class PointerProgressIndicator extends StatelessWidget {
Widget build(BuildContext context) {
final theme = Theme.of(context);
final defaultColor = theme.colorScheme.onBackground;
final blockedColor = theme.stateColors.alarmLowLevel;
final currentColor = (_value == 0 || _value == 1) ? blockedColor : defaultColor;
final currentColor = _color ?? defaultColor;
return SizedBox(
height: _minHeight,
child: Stack(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:hmi_core/hmi_core.dart';
import 'package:hmi_core/hmi_core_app_settings.dart';
Expand All @@ -14,30 +15,45 @@ class SmallLinearValueIndicator extends StatelessWidget {
final Widget? _caption;
final String _valueUnit;
final double _textIndicatorWidth;
final double _min;
final double _max;
final double? _high;
final double? _low;
final Stream<DsDataPoint<num>> _stream;
final IndicationStyle _indicationStyle;
final Color? _defaultColor;
///
const SmallLinearValueIndicator({
super.key,
required Stream<DsDataPoint<num>> stream,
required double max,
double min = 0.0,
double? high,
double? low,
Widget? caption,
String valueUnit = '',
double textIndicatorWidth = 55,
IndicationStyle indicationStyle = IndicationStyle.pointer,
Color? defaultColor,
}) : _indicationStyle = indicationStyle,
_stream = stream,
_min = min,
_max = max,
_high = high,
_low = low,
_caption = caption,
_valueUnit = valueUnit,
_textIndicatorWidth = textIndicatorWidth;
_textIndicatorWidth = textIndicatorWidth,
_defaultColor = defaultColor;
//
@override
Widget build(BuildContext context) {
final delta = (_max - _min).abs();
final caption = _caption;
final padding = const Setting('padding').toDouble;
final smallPadding = const Setting('smallPadding').toDouble;
final theme = Theme.of(context);
final alarmColor = theme.stateColors.alarm;
return Card(
margin: EdgeInsets.zero,
child: Padding(
Expand All @@ -63,18 +79,27 @@ class SmallLinearValueIndicator extends StatelessWidget {
stream: _stream,
builder:(context, snapshot) {
final indicatorHeight = smallPadding * 3;
final value = (snapshot.data?.value.toDouble() ?? 0.0) / _max;
final snapshotValue = min(
max(
snapshot.data?.value.toDouble() ?? _min,
_min,
),
_max,
);
final percantage = (snapshotValue - _min) / delta;
final isAlarm = _isAlarm(snapshotValue);
switch(_indicationStyle) {
case IndicationStyle.bar:
return LinearProgressIndicator(
value: value,
value: percantage,
minHeight: indicatorHeight,
color: Theme.of(context).stateColors.on,
color: isAlarm ? alarmColor : _defaultColor,
);
case IndicationStyle.pointer:
return PointerProgressIndicator(
value: value,
value: percantage,
minHeight: indicatorHeight,
color: isAlarm ? alarmColor : _defaultColor,
);
}
},
Expand All @@ -101,4 +126,12 @@ class SmallLinearValueIndicator extends StatelessWidget {
),
);
}

bool _isAlarm(double currentValue) {
final low = _low;
final high = _high;
final isAlarmLow = low != null && currentValue - low < 0;
final isAlarmHigh = high != null && currentValue - high > 0;
return isAlarmLow || isAlarmHigh;
}
}