Skip to content

Commit

Permalink
Improve performance of number bar and slider labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 16, 2024
1 parent 78a861c commit 9dca851
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/widgets/nt_widgets/single_topic/number_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class NumberBar extends NTWidget {
Widget build(BuildContext context) {
NumberBarModel model = cast(context.watch<NTWidgetModel>());

String formatLabel(num input) =>
input.toStringAsFixed(input.truncateToDouble() == input ? 0 : 2);

return ValueListenableBuilder(
valueListenable: model.subscription!,
builder: (context, data, child) {
Expand Down Expand Up @@ -262,8 +265,7 @@ class NumberBar extends NTWidget {
if (model.divisions != null)
for (int i = 0; i < model.divisions!; i++)
CustomRulerLabel(
text: (model.minValue + divisionInterval! * i)
.toStringAsFixed(2),
text: formatLabel(model.minValue + divisionInterval! * i),
value: model.minValue + divisionInterval * i,
),
],
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/nt_widgets/single_topic/voltage_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class VoltageView extends NTWidget {
Widget build(BuildContext context) {
VoltageViewModel model = cast(context.watch<NTWidgetModel>());

String formatLabel(num input) =>
input.toStringAsFixed(input.truncateToDouble() == input ? 0 : 2);

return ValueListenableBuilder(
valueListenable: model.subscription!,
builder: (context, data, child) {
Expand Down Expand Up @@ -263,7 +266,7 @@ class VoltageView extends NTWidget {
for (int i = 0; i < model.divisions!; i++)
CustomRulerLabel(
text:
'${(model.minValue + divisionInterval! * i).toStringAsFixed(2)} V',
'${formatLabel(model.minValue + divisionInterval! * i)} V',
value: model.minValue + divisionInterval * i,
),
],
Expand Down

0 comments on commit 9dca851

Please sign in to comment.