Skip to content

Commit

Permalink
SmallLinearValueIndicator | Added alarm boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Minyewoo committed Jun 20, 2023
1 parent 3dbc646 commit 44e65dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
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
Expand Up @@ -17,32 +17,43 @@ class SmallLinearValueIndicator extends StatelessWidget {
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 @@ -68,21 +79,27 @@ class SmallLinearValueIndicator extends StatelessWidget {
stream: _stream,
builder:(context, snapshot) {
final indicatorHeight = smallPadding * 3;
final snapshotValue = snapshot.data?.value.toDouble();
final value = snapshotValue == null
? 0.0
: (max(snapshotValue, _min) - _min) / delta;
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 @@ -109,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;
}
}

0 comments on commit 44e65dc

Please sign in to comment.