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
Changes from 3 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,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,6 +15,7 @@ class SmallLinearValueIndicator extends StatelessWidget {
final Widget? _caption;
final String _valueUnit;
final double _textIndicatorWidth;
final double _min;
final double _max;
final Stream<DsDataPoint<num>> _stream;
final IndicationStyle _indicationStyle;
Expand All @@ -22,19 +24,22 @@ class SmallLinearValueIndicator extends StatelessWidget {
super.key,
required Stream<DsDataPoint<num>> stream,
required double max,
double min = 0.0,
Widget? caption,
String valueUnit = '',
double textIndicatorWidth = 55,
IndicationStyle indicationStyle = IndicationStyle.pointer,
}) : _indicationStyle = indicationStyle,
_stream = stream,
_min = min,
_max = max,
_caption = caption,
_valueUnit = valueUnit,
_textIndicatorWidth = textIndicatorWidth;
//
@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;
Expand Down Expand Up @@ -63,7 +68,10 @@ class SmallLinearValueIndicator extends StatelessWidget {
stream: _stream,
builder:(context, snapshot) {
final indicatorHeight = smallPadding * 3;
final value = (snapshot.data?.value.toDouble() ?? 0.0) / _max;
final snapshotValue = snapshot.data?.value.toDouble();
final value = snapshotValue == null
? 0.0
: (max(snapshotValue, _min) - _min) / delta;
switch(_indicationStyle) {
case IndicationStyle.bar:
return LinearProgressIndicator(
Expand Down