Problem with trigger in nested list item in Flutter runtime
I have a list buttonList that is populated by instances of a component (Button Component) that has its own view model, buttonVM.
This component has a trigger, isClicked, which is fired when the component is clicked. The button moves and I eventually want to get to the point where panel with details are opened up in the app.
In flutter, the existing contents of the list are cleared, then new button instances are added to the list, and a listener for the isClicked trigger is added to that instance. At the moment, the trigger should just log the fact that it has been clicked.
Visually, it plays as it should, the button moves and plays a sound as expected, however the trigger doesn’t seem to be registering or logging.
Any ideas on how I can fix this?
Here is the relevant bit of code:
// Create buttonList
final buttonList = rootVM.list("buttonList");
if (buttonList != null) {
// Clear any editor-time placeholder buttons in the list
while (buttonList.length > 0) {
buttonList.removeAt(buttonList.length - 1);
}
// Create button loop
for (int i = 0; i < 8; i++) {
final buttonInstanceVM = riveFile.viewModelByName("ButtonVM")!;
final buttonInstance = buttonInstanceVM.createInstance()!;
if (buttonInstance != null) {
try {
// Set button values
buttonInstance.number("buttonNum")?.value = (i + 1).toDouble();
buttonInstance.number("positionPercentage")?.value =
((i + 1) * 10).toDouble();
buttonInstance.boolean("buttonComplete")?.value = false;
developer.log("Configuring button: ${i + 1}");
// Add button to list
buttonList.add(buttonInstance);
controller.advance(0.1);
// Attach the listener to the trigger property
final trigger = buttonInstance.trigger("isClicked");
if (trigger != null) {
developer.log("Trigger ${i + 1} added.");
trigger.addListener((bool value) {
// Triggers fire when the value transitions to true
if (value && mounted) {
developer.log(
"CLICKED: Milestone ${i + 1} confirmed via Data Binding!");
}
});
} else {
developer
.log("WARNING: 'isClicked' trigger not found on ButtonVM!");
}
} catch (e) {
developer.log("Error in button loop at index $i: $e");
}
}
} // Add Buttons
} // Button List