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

Instance member 'setCurrentScreen' can't be accessed using static access

我正在尝试将 Firebase Analytics 添加到我的 flutter 应用程序中,以在仪表板上显示不同的屏幕名称。我在 link 中使用了在 Whosebug 上找到的方法:

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

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 方法运行不正常,应用程序未构建。关于我可以做些什么来构建它的任何建议。

来自 screen tracking 上的 FlutterFire 文档:

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