Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 25b648d

Browse files
authored
Move various first-party plugins into this repo (#36)
* Added image_picker * Added firebase_analytics * Added firebase_storage * Added google_sign_in * Added firebase_auth * Added firebase_database
1 parent de9233c commit 25b648d

File tree

356 files changed

+12132
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

356 files changed

+12132
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/firebase_analytics/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2017, the Flutter project authors. All rights reserved.
2+
Redistribution and use in source and binary forms, with or without
3+
modification, are permitted provided that the following conditions are
4+
met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/firebase_analytics/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Firebase Analytics for Flutter
2+
3+
**WARNING: this is incomplete and highly experimental**
4+
5+
This plugin allows Flutter apps use the Firebase Analytics API from their Dart
6+
code.
7+
8+
## Getting Started
9+
10+
The the `example` directory for a sample app using Firebase Analytics.
11+
12+
To learn more about Flutter plugins, view our online
13+
[documentation](https://flutter.io/platform-plugins).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
group 'io.flutter.firebase_analytics'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 25
24+
buildToolsVersion '25.0.2'
25+
26+
defaultConfig {
27+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
28+
}
29+
lintOptions {
30+
disable 'InvalidPackage'
31+
}
32+
dependencies {
33+
compile 'com.google.firebase:firebase-auth:10.2.1'
34+
compile 'com.google.firebase:firebase-analytics:10.2.1'
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'firebase_analytics'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.firebase_analytics"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
7+
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9+
<uses-permission android:name="android.permission.INTERNET" />
10+
<uses-permission android:name="android.permission.WAKE_LOCK" />
11+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.firebase_analytics;
6+
7+
import java.util.Map;
8+
9+
import com.google.firebase.FirebaseApp;
10+
import com.google.firebase.analytics.FirebaseAnalytics;
11+
12+
import android.app.Activity;
13+
import android.os.Bundle;
14+
15+
import io.flutter.plugin.common.MethodChannel;
16+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
17+
import io.flutter.plugin.common.MethodChannel.Result;
18+
import io.flutter.plugin.common.MethodCall;
19+
import io.flutter.plugin.common.PluginRegistry;
20+
21+
/**
22+
* Flutter plugin for Firebase Analytics.
23+
*/
24+
public class FirebaseAnalyticsPlugin implements MethodCallHandler {
25+
private final Activity activity;
26+
private final FirebaseAnalytics firebaseAnalytics;
27+
28+
public static void registerWith(PluginRegistry.Registrar registrar) {
29+
final MethodChannel channel = new MethodChannel(registrar.messenger(), "firebase_analytics");
30+
channel.setMethodCallHandler(new FirebaseAnalyticsPlugin(registrar.activity()));
31+
}
32+
33+
private FirebaseAnalyticsPlugin(Activity activity) {
34+
this.activity = activity;
35+
FirebaseApp.initializeApp(activity);
36+
this.firebaseAnalytics = FirebaseAnalytics.getInstance(activity);
37+
}
38+
39+
@Override
40+
public void onMethodCall(MethodCall call, Result result) {
41+
switch (call.method) {
42+
case "logEvent":
43+
handleLogEvent(call, result);
44+
break;
45+
case "setUserId":
46+
handleSetUserId(call, result);
47+
break;
48+
case "setCurrentScreen":
49+
handleSetCurrentScreen(call, result);
50+
break;
51+
case "setAnalyticsCollectionEnabled":
52+
handleSetAnalyticsCollectionEnabled(call, result);
53+
break;
54+
case "setMinimumSessionDuration":
55+
handleSetMinimumSessionDuration(call, result);
56+
break;
57+
case "setSessionTimeoutDuration":
58+
handleSetSessionTimeoutDuration(call, result);
59+
break;
60+
case "setUserProperty":
61+
handleSetUserProperty(call, result);
62+
break;
63+
default:
64+
result.notImplemented();
65+
break;
66+
}
67+
}
68+
69+
private void handleLogEvent(MethodCall call, Result result) {
70+
@SuppressWarnings("unchecked")
71+
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
72+
final String eventName = (String) arguments.get("name");
73+
74+
@SuppressWarnings("unchecked")
75+
final Bundle parameterBundle = createBundleFromMap((Map<String, Object>) arguments.get("parameters"));
76+
firebaseAnalytics.logEvent(eventName, parameterBundle);
77+
result.success(null);
78+
}
79+
80+
private void handleSetUserId(MethodCall call, Result result) {
81+
final String id = (String) call.arguments;
82+
firebaseAnalytics.setUserId(id);
83+
result.success(null);
84+
}
85+
86+
private void handleSetCurrentScreen(MethodCall call, Result result) {
87+
@SuppressWarnings("unchecked")
88+
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
89+
final String screenName = (String) arguments.get("screenName");
90+
final String screenClassOverride = (String) arguments.get("screenClassOverride");
91+
92+
firebaseAnalytics.setCurrentScreen(activity, screenName, screenClassOverride);
93+
result.success(null);
94+
}
95+
96+
private void handleSetAnalyticsCollectionEnabled(MethodCall call, Result result) {
97+
final Boolean enabled = (Boolean) call.arguments;
98+
firebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
99+
result.success(null);
100+
}
101+
102+
private void handleSetMinimumSessionDuration(MethodCall call, Result result) {
103+
final Integer milliseconds = (Integer) call.arguments;
104+
firebaseAnalytics.setMinimumSessionDuration(milliseconds);
105+
result.success(null);
106+
}
107+
108+
private void handleSetSessionTimeoutDuration(MethodCall call, Result result) {
109+
final Integer milliseconds = (Integer) call.arguments;
110+
firebaseAnalytics.setSessionTimeoutDuration(milliseconds);
111+
result.success(null);
112+
}
113+
114+
private void handleSetUserProperty(MethodCall call, Result result) {
115+
@SuppressWarnings("unchecked")
116+
Map<String, Object> arguments = (Map<String, Object>) call.arguments;
117+
final String name = (String) arguments.get("name");
118+
final String value = (String) arguments.get("value");
119+
120+
firebaseAnalytics.setUserProperty(name, value);
121+
result.success(null);
122+
}
123+
124+
private static Bundle createBundleFromMap(Map<String, Object> map) {
125+
if (map == null) {
126+
return null;
127+
}
128+
129+
Bundle bundle = new Bundle();
130+
for (Map.Entry<String, Object> jsonParam : map.entrySet()) {
131+
final Object value = jsonParam.getValue();
132+
final String key = jsonParam.getKey();
133+
if (value instanceof String) {
134+
bundle.putString(key, (String) value);
135+
} else if (value instanceof Integer) {
136+
bundle.putInt(key, (Integer) value);
137+
} else if (value instanceof Double) {
138+
bundle.putDouble(key, (Double) value);
139+
} else if (value instanceof Boolean) {
140+
bundle.putBoolean(key, (Boolean) value);
141+
} else {
142+
throw new IllegalArgumentException("Unsupported value type: " + value.getClass().getCanonicalName());
143+
}
144+
}
145+
return bundle;
146+
}
147+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock
10+
.flutter-plugins
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# firebase_analytics_example
2+
3+
Demonstrates how to use the firebase_analytics plugin.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter, view our online
8+
[documentation](http://flutter.io/).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$/android">
6+
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
7+
</content>
8+
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="Flutter for Android" level="project" />
11+
</component>
12+
</module>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withInputStream { stream ->
5+
localProperties.load(stream)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
apply plugin: 'com.android.application'
15+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
16+
17+
android {
18+
compileSdkVersion 25
19+
buildToolsVersion '25.0.2'
20+
21+
lintOptions {
22+
disable 'InvalidPackage'
23+
}
24+
25+
defaultConfig {
26+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
27+
}
28+
29+
buildTypes {
30+
release {
31+
// TODO: Add your own signing config for the release build.
32+
// Signing with the debug keys for now, so `flutter run --release` works.
33+
signingConfig signingConfigs.debug
34+
}
35+
}
36+
}
37+
38+
flutter {
39+
source '../..'
40+
}
41+
42+
dependencies {
43+
compile 'com.google.firebase:firebase-core:10.0.1'
44+
}
45+
46+
apply plugin: 'com.google.gms.google-services'

0 commit comments

Comments
 (0)