无法将我的 Flutter 应用程序连接到 firebase 分析

问题描述 投票:0回答:1

我正在尝试使用 Firebase 分析连接并记录事件日志,但没有任何进展,我已经集成了 Firebase 谷歌登录方法,但无法使用 Firebase 分析来执行此操作。 这是到目前为止我所做的所有改变 添加了

implementation 'com.google.firebase:firebase-analytics' 

在依赖项中的应用程序级别 build.gradle 中 还安装了 firebase 和 firebase_analytics 软件包,我仍然无法记录事件

flutter firebase google-analytics firebase-analytics
1个回答
0
投票

在 android/app/build.gradle 添加

apply plugin: 'com.google.gms.google-services'
//Firebase
implementation platform('com.google.firebase:firebase-bom:31.2.2')
implementation 'com.google.firebase:firebase-analytics'```

在 android/build.gradle 添加

classpath 'com.google.gms:google-services:4.3.15'

在 pubspec.yaml 添加

firebase_core: ^2.7.0
firebase_analytics: ^10.1.4

这里是示例演示

import 'dart:io';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/material.dart';

class MyRouteObserver extends RouteObserver<PageRoute<dynamic>> {
  @override
  void didPush(Route route, Route? previousRoute) async {
    if(route.settings.name.toString().toLowerCase().replaceAll("/", "").isNotEmpty){
      await FirebaseAnalytics.instance.logEvent(
        name: Platform.isIOS
            ? "ios_${route.settings.name.toString().toLowerCase().replaceAll("/", "")}"
            : route.settings.name.toString().toLowerCase().replaceAll("/", ""),
        parameters: {},
      );
    }

    super.didPush(route, previousRoute);
  }
}

在lib/main.dart中添加MaterialApp中的这一行

navigatorObservers: [MyRouteObserver()],

不要忘记初始化 Firebase

await Firebase.initializeApp();
© www.soinside.com 2019 - 2024. All rights reserved.