Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The argument type 'ModalRoute<Object?>?' can't be assigned to the parameter type 'PageRoute<dynamic>'

Recently I am migrating to null safety. Updated the firebase_analytics: ^8.0.2.

Now facing problem with this.observer.subscribe(this, ModalRoute.of(context)); Can some one help what to pass second argument.

class _BookedClassDetailsPageState extends 
State<BookedClassDetailsPage> with SingleTickerProviderStateMixin, RouteAware{

late FirebaseAnalyticsObserver observer;

@override
void initState() {
 super.initState();
 observer=widget.repository.analyticsService.getAnalyticsObserver();
 observer.analytics.setCurrentScreen(
     screenName: 'Booked Class Page',
     screenClassOverride: 'BookedClassPage'
 );

}

@override
void didChangeDependencies() {
  super.didChangeDependencies();
  observer.subscribe(this, ModalRoute.of(context));
}
 @override
 void dispose() {
    observer.unsubscribe(this);
    super.dispose();
 }
}
like image 501
BLB Avatar asked Apr 30 '21 09:04

BLB


1 Answers

you can change the type ModalRoute to PageRoute via key word "as", like this:

observer.subscribe(this, ModalRoute.of(context) as PageRoute);
like image 122
shilin Avatar answered Oct 21 '22 01:10

shilin