无法使用静态访问访问实例成员'setCurrentScreen'



我正试图将Firebase Analytics添加到我的flutter应用程序中,以便在仪表板上显示不同的屏幕名称。我使用了我在stackoverflow上找到的一个方法:如何在Firebase分析中跟踪Flutter屏幕?

我在一个单独的文件中添加了这个代码:

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/widgets.dart';
// A Navigator observer that notifies RouteAwares of changes to state of their Route
final routeObserver = RouteObserver<PageRoute>();
mixin RouteAwareAnalytics<T extends StatefulWidget> on State<T>
implements RouteAware {
AnalyticsRoute get route;
@override
void didChangeDependencies() {
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute<dynamic>);
super.didChangeDependencies();
}
@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
}
@override
void didPop() {}
@override
void didPopNext() {
// Called when the top route has been popped off,
// and the current route shows up.
_setCurrentScreen(route);
}
@override
void didPush() {
// Called when the current route has been pushed.
_setCurrentScreen(route);
}
@override
void didPushNext() {}
Future<void> _setCurrentScreen(AnalyticsRoute analyticsRoute) {
print('Setting current screen to $analyticsRoute');
return FirebaseAnalytics.**setCurrentScreen**(
screenName: screenName(analyticsRoute),
screenClassOverride: screenClass(analyticsRoute),
);
}
}
enum AnalyticsRoute { screenName }
String screenClass(AnalyticsRoute route) {
switch (route) {
case AnalyticsRoute.screenName:
return 'screenName';
}
throw ArgumentError.notNull('route');
}
String screenName(AnalyticsRoute route) {
switch (route) {
case AnalyticsRoute.screenName:
return '/screenName';
}
throw ArgumentError.notNull('route');
}

然后,我在屏幕中添加了要跟踪的路线观察器。setCurrentScreen方法工作不正常,应用程序未生成。关于我可以做些什么来构建它的任何建议。

来自FlutterFire关于屏幕跟踪的文档:

await FirebaseAnalytics.instance
.setCurrentScreen(
screenName: 'Products'
);

相关内容

  • 没有找到相关文章