Skip to content

Commit

Permalink
Fixed multi-topic widgets constantly rebuilding themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Feb 25, 2024
1 parent dfd338a commit b47cc9f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
1 change: 0 additions & 1 deletion lib/widgets/nt_widgets/multi-topic/basic_swerve_drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ class BasicSwerveModel extends NTWidgetModel {
backRightAngle,
backRightVelocity,
robotAngle,
_showRobotRotation,
];
}

Expand Down
7 changes: 6 additions & 1 deletion lib/widgets/nt_widgets/multi-topic/combo_box_chooser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ class ComboBoxChooserModel extends NTWidgetModel {
String defaultOption =
tryCast(ntConnection.getLastAnnouncedValue(defaultTopicName)) ?? '';

return [options, active, selected, defaultOption];
return [
...options,
active,
selected,
defaultOption,
];
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nt_widgets/multi-topic/command_scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CommandSchedulerModel extends NTWidgetModel {
List<String> names = rawNames.whereType<String>().toList();
List<int> ids = rawIds.whereType<int>().toList();

return [names, ids];
return [...names, ...ids];
}
}

Expand Down
25 changes: 8 additions & 17 deletions lib/widgets/nt_widgets/multi-topic/field_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class FieldWidgetModel extends NTWidgetModel {

List<double> robotPosition = robotPositionRaw.whereType<double>().toList();

data.add(robotPosition);
data.addAll(robotPosition);

if (_showOtherObjects || _showTrajectories) {
for (String objectTopic in _otherObjectTopics) {
Expand All @@ -306,34 +306,25 @@ class FieldWidgetModel extends NTWidgetModel {
List<double> objectPosition =
objectPositionRaw.whereType<double>().toList();

data.add(objectPosition);
data.addAll(objectPosition);
}
}

data.addAll([
_showOtherObjects,
_showTrajectories,
_robotWidthMeters,
_robotLengthMeters,
_otherObjectTopics,
_fieldGame,
]);

return data;
}

@override
Stream<Object> get multiTopicPeriodicStream async* {
yield Object();

List<Object> previousData = getCurrentData();
int previousHash = Object.hashAll(getCurrentData());

while (true) {
List<Object> currentData = getCurrentData();
int currentHash = Object.hashAll(getCurrentData());

if (previousData.hashCode != currentData.hashCode) {
if (previousHash != currentHash) {
yield Object();
previousData = currentData;
previousHash = currentHash;
} else if (!rendered) {
yield Object();
}
Expand Down Expand Up @@ -535,12 +526,12 @@ class FieldWidget extends NTWidget {
double scaleReduction = (_getBackgroundFitWidth(model, size)) /
(model.field.fieldImageWidth ?? 1);

if (renderBox != null &&
if (!model.rendered &&
renderBox != null &&
model.widgetSize != null &&
size != const Size(0, 0) &&
size.width > 100.0 &&
scaleReduction != 0.0 &&
robotPosition != null &&
fieldCenter != const Offset(0.0, 0.0) &&
model.field.fieldImageLoaded) {
model.rendered = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/nt_widgets/multi-topic/network_alerts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NetworkAlertsModel extends NTWidgetModel {
List<String> warnings = warningsRaw.whereType<String>().toList();
List<String> infos = infosRaw.whereType<String>().toList();

return [errors, warnings, infos];
return [...errors, ...warnings, ...infos];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SplitButtonChooserModel extends NTWidgetModel {
String defaultOption =
tryCast(ntConnection.getLastAnnouncedValue(defaultTopicName)) ?? '';

return [options, active, selected, defaultOption];
return [...options, active, selected, defaultOption];
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/widgets/nt_widgets/multi-topic/yagsl_swerve_drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class YAGSLSwerveDriveModel extends NTWidgetModel {
rotationUnit,
robotAngle,
maxSpeed,
_showRobotRotation,
];
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/nt_widgets/nt_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ class NTWidgetModel extends ChangeNotifier {
}

Stream<Object> get multiTopicPeriodicStream async* {
int previousData = Object.hashAll(getCurrentData());
int previousHash = Object.hashAll(getCurrentData());

while (true) {
int currentData = Object.hashAll(getCurrentData());
int currentHash = Object.hashAll(getCurrentData());

if (previousData != currentData) {
if (previousHash != currentHash) {
yield Object();
previousData = currentData;
previousHash = currentHash;
}

await Future.delayed(Duration(
Expand Down

0 comments on commit b47cc9f

Please sign in to comment.