flutter firebase接入

news/2024/5/20 5:26:07 标签: android, gradle

firebase的功能

  • 实时数据库(Realtime database)
  • 用户认证(Authentication)
  • 自定义API(Cloud function)
  • 消息推送(Cloud messaging)
  • 静态网页Hosting
  • 云存储(Cloud storage)
  • 实时监控(Analytics)

点击 console.firebase.google.com
这个过程可以下载两个文件 Android 为 google-services.json。IOS 为 GoogleService-Info.plist

Android 接入

buildscript {
    ......
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0' //firebase 注意 Android studio 提示版本进行更新
    }
}
dependencies {
    ......
    implementation 'com.google.firebase:firebase-core:16.0.7' //firebase 注意 Android studio 提示版本进行更新
}
 
apply plugin: 'com.google.gms.google-services' //firebase支持 加到最后一行

IOS 接入

  • 下载 GoogleService-Info.plist 到 ios/Runner/GoogleService-Info.plist 如果xcode读取不到文件 需要导入到项目
  • 修改 ios/Runner/AppDelegate.swift
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
 
@import Firebase;//增加 firebase 支持
 
@implementation AppDelegate
 
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [FIRApp configure];//增加 firebase 支持
    
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
 

完成以上步骤后 删除app 重新 flutter run -v 可以看到 firebase 相关日志 最后ios 跟安卓都会出现 成功提示如下图

firebase_analytics 库引入

  • 修改 pubspec.yaml 增加
dependencies:
  firebase_analytics: ^2.0.3


  flutter packages get

封装工具包并且引入到项目

lib/utils/analytics.dart

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
 
//统计
FirebaseAnalytics analytics = FirebaseAnalytics();
FirebaseAnalyticsObserver observer =
    FirebaseAnalyticsObserver(analytics: analytics);
    

lib/main.dart

import 'package:efox_flutter/utils/analytics.dart' as Analytics;
......
class MainAppState extends State<MainApp> {
  @override
  Widget build(BuildContext context) {
    MaterialApp(
        ......
        navigatorObservers: <NavigatorObserver>[Analytics.observer],//加入路由统计
      );
  }
}

其他调用

import 'package:efox_flutter/utils/analytics.dart' show analytics;
analytics.logEvent(name: 'component', parameters: {'name': itemInfo.title});

增加上面代码后需要在firebase 管理后台增加 name关键字统计


http://www.niftyadmin.cn/n/1579452.html

相关文章

flutter siwper用法与参数

安装 一键三连 flutter_swiper: ^1.0.6flutter packages get import package:flutter_swiper/flutter_swiper.dart; body: Container(width: MediaQuery.of(context).size.width,height: 200.0,child: Swiper(itemBuilder: (BuildContext context, int index) {return (Image…

jquery 自动隐藏easyui的导航west区域

1.前言. 通过live可以实现页面载入后自动点击&#xff0c;完成一些其他操作完成不了的任务。这个功能可以用在easyui页面载入的时候&#xff0c;进行自动收缩&#xff0c;把左边west的region隐藏。实现曲径通幽的效果。 2.代码片段示例&#xff08;隐藏easyui的west 。 $("…

前端性能优化总结 ~进阶篇

简短概括 前端性能优化前端性能监控框架性能优化 一、前端性能优化 从输入url到页面展现发生了什么&#xff1f;&#xff08;前端必了解&#xff0c;优化的重点&#xff09;网络优化浏览器优化 先简单概括一下输入URL并回车发的过程&#xff1b; 回车DNS解析&#xff1a;将…

转:FSMT:文件服务器从03迁移到08R2实战演练

另外参见&#xff1a;http://www.canway.net/Lists/CanwayOriginalArticels/DispForm.aspx?ID282 以前做过一个项目&#xff0c;是把文件服务器从03升级到08 R2&#xff0c;使用的当然就是我们微软官方的FSMT工具&#xff0c;但由于当时非常着急&#xff0c;也不清楚FSMT的性能…

nuxt项目总结-综合

nuxt项目总结技术栈选择依赖nuxt的生命周期&#xff08;及其重要&#xff0c;学习框架必须了解生命周期&#xff0c;及其原理&#xff09;基于nuxt的axios二次封装为何能够SEO优化使用SSR所解决的问题SSR渲染原理为什么要用引入node中间层使用SSR最难处理的点Vue&#xff08;nu…

Ubuntu共享WiFi(AP)给Android方法

更新: 2012-03-03 Android是不支持Ad-hoc模式的WiFi.Windows 7软AP一个还是比较简单的.本文介绍在Ubuntu下实现软AP.(需要你的无线网卡支持AP哈) 使用工具hostapd&#xff0c;dnsmasq.我的环境时Ubuntu10.10;手机Android 2.1;网卡ath5k.有线网络使用静态的IP. 首先&#xff0c;…

nuxt项目总结-设计

nuxt项目总结路由设计前端分类设计页面设计前端安全设计路由设计 根据设计图设计出&#xff1a; 设计前要想清楚每一个页面为什么放置该处 路由 ├─page │ ├─ClassificationTemplate │ │ │——details │ │ │ └─_productId.vue │ │ └─_classId.vue │ ├─Do…

ActiveMQ学习笔记(一) JMS概要

(一)什么是JMS jms即Java消息服务&#xff08;Java Message Service&#xff09;应用程序接口是一个Java平台中关于面向消息中间件&#xff08;MOM&#xff09;的API&#xff0c;用于在两个应用程序之间&#xff0c;或分布式系统中发送消息&#xff0c;进行异步通信。Java消息服…