Updating view model in Flutter does not reflect in Animation
Hi all! With the update to 0.14.0 I’ve had to redo most of my data binding in the animations that I use in a Flutter app. Previously I just used root variables, but now I switched to the recommended view models, since the other method is deprecated.
I have an artboard linked to a ViewModel with the instance name “Instance”. The definition contains a boolean variable “light”, which is set to true by default. This boolean is used in a statemachine (“Default”) to transition to a different state in an animation.
I have also added a “heartbeat” loop layer to my state machine to ensure that the animation keeps on updating. Now when I hit “play” in Rive, and change the value of the view model, the animation responds exactly as intended.
I have exported the file to be used in Flutter, there I’ve imported it and loaded it through:
RiveWidgetBuilder(
fileLoader: _fileLoader,
artboardSelector: ArtboardSelector.byName(widget.artboardName),
stateMachineSelector:
StateMachineSelector.byName(widget.stateMachineName),
dataBind: DataBind.auto(),
onLoaded: (state) {
mainViewModel = state.viewModelInstance!;
currentBrightness = MediaQuery.of(context).platformBrightness;
initVars();
},
builder: (context, state) => switch (state) {
RiveLoading() => const Center(child: CircularProgressIndicator()),
RiveFailed() => ErrorWidget.withDetails(
message: state.error.toString(),
error: FlutterError(state.error.toString()),
),
RiveLoaded() => RiveWidget(controller: state.controller),
},
);initVars takes care of linking the view model variables to my flutter widget code as such:
void initVars() async {
_light = mainViewModel!.boolean('light')!;
_light.value = currentBrightness == Brightness.light;
}When I then debug, all variables show the expected default values as I defined in Rive. But when I update _light.value, the view model data changes, but nothing happens to my animation.
What am I missing?