diff --git a/lib/src/indicators/value_indicators/pointer_progress_indicator.dart b/lib/src/indicators/value_indicators/pointer_progress_indicator.dart index dc83d7d..caf0b73 100644 --- a/lib/src/indicators/value_indicators/pointer_progress_indicator.dart +++ b/lib/src/indicators/value_indicators/pointer_progress_indicator.dart @@ -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; @@ -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( diff --git a/lib/src/indicators/value_indicators/small_linear_value_indicator.dart b/lib/src/indicators/value_indicators/small_linear_value_indicator.dart index 4a7413f..3cf0218 100644 --- a/lib/src/indicators/value_indicators/small_linear_value_indicator.dart +++ b/lib/src/indicators/value_indicators/small_linear_value_indicator.dart @@ -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'; @@ -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> _stream; final IndicationStyle _indicationStyle; + final Color? _defaultColor; /// const SmallLinearValueIndicator({ super.key, required Stream> 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( @@ -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, ); } }, @@ -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; + } }