I want to setState() of the widget after navigating from a particular widget,

for this, I am using route observer as mentioned in this official link

for the above requirement, I need to know the widget which I navigated from and if it matches the required widget then I will setState() in this widget.

in the docs didPop() takes the arguments Route route, Route previous route

but in the widget when passing the argument like

class _MainPageState extends State<MainPage> with RouteAware {
   @override
   void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
      print("oh oooo yes");
   }
 }

flutter is giving the error

'_MainPageState.didPop' ('void Function(Route<dynamic>, Route<dynamic>)') isn't a valid override of 
 'RouteAware.didPop' ('void Function()').dart(invalid_override)

what is the problem here?


Solution 1: Rémi Rousselet

You are confusing RouteAware and RouteObserver.

RouteAware's didPop does not receive any parameter. It is RouteObserver's didPop that do.

The thing is, what is mixed in on widgets is RouteAware, not RouteObserver. As such, widgets do not receive the current/previous routes.

Consider subclassing NavigatorObserver/RouteObserver and bake something on your own if you need something advanced.