0

I have a Widget that based on certain user interactions modifies the AnimationController of the PageRoute.

It does this via ModalRoute.of(context)?.controller and whilst it works as expected it is flagged as an invalid use of a protected member.

static void animateController(BuildContext context, double value){
  route?.controller  // flag
        ?.animateTo(
          value.clamp(0, 1),
          curve: Curves.easeOutCubic,
          duration: Duration(milliseconds: 360),
        )
}

// flag :: The member 'controller' can only be used within instance members of subclasses of 'package:flutter/src/widgets/routes.dart'.dart(invalid_use_of_protected_member)

Whilst this still works, clearly it is not the correct approach. I could build a custom PageRoute<T>, a separate InheritedWidget that contains the controller and then create a static function but that seems quite unnecessary when it works with ModalRoute.

I presume I'm getting this flag because the controller is annotated as protected. What is the best way to access and adjust this controller in child widgets.

Walrus
  • 19,801
  • 35
  • 121
  • 199

0 Answers0