ComponentRef exposes Riverpod functionality to individual Components, and is comparable to flutter_riverpod’s WidgetRef.


RiverpodComponentMixin manages the lifecycle of listeners on behalf of individual Components.

Components using this mixin must use addToGameWidgetBuild in their onMount method to add listeners (e.g. or ref.listen) prior to calling super.onMount, which manages the staged listeners and disposes of them on the user’s behalf inside onRemove.

class RiverpodAwareTextComponent extends PositionComponent
    with RiverpodComponentMixin {
  late TextComponent textComponent;
  int currentValue = 0;

  void onMount() {
    addToGameWidgetBuild(() {
      ref.listen(countingStreamProvider, (p0, p1) {
        if (p1.hasValue) {
          currentValue = p1.value!;
          textComponent.text = '$currentValue';
    add(textComponent = TextComponent(position: position + Vector2(0, 27)));


RiverpodGameMixin provides listeners from all components to the build method of the RiverpodAwareGameWidget.