Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/firebase_database/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.4

* Updated transactions implementation on Android for compatibility with
newer versions of Flutter engine that require channel calls be made
on the UI thread.

## 3.0.3

* Automatically use version from pubspec.yaml when reporting usage to Firebase.
Expand All @@ -10,6 +16,7 @@
## 3.0.1

* Suppress deprecation warning for BinaryMessages. See: https://github.com/flutter/flutter/issues/33446
>>>>>>> origin/master
## 3.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.firebase.database;

import android.app.Activity;
import android.util.Log;
import android.util.SparseArray;
import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class FirebaseDatabasePlugin implements MethodCallHandler {
private static final String TAG = "FirebaseDatabasePlugin";

private final MethodChannel channel;
private final Activity activity;
private static final String EVENT_TYPE_CHILD_ADDED = "_EventType.childAdded";
private static final String EVENT_TYPE_CHILD_REMOVED = "_EventType.childRemoved";
private static final String EVENT_TYPE_CHILD_CHANGED = "_EventType.childChanged";
Expand All @@ -50,11 +52,12 @@ public class FirebaseDatabasePlugin implements MethodCallHandler {
public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_database");
channel.setMethodCallHandler(new FirebaseDatabasePlugin(channel));
channel.setMethodCallHandler(new FirebaseDatabasePlugin(channel, registrar.activity()));
}

private FirebaseDatabasePlugin(MethodChannel channel) {
private FirebaseDatabasePlugin(MethodChannel channel, Activity activity) {
this.channel = channel;
this.activity = activity;
}

private DatabaseReference getReference(FirebaseDatabase database, Map<String, Object> arguments) {
Expand Down Expand Up @@ -333,7 +336,7 @@ public Transaction.Result doTransaction(MutableData mutableData) {
final Task<Map<String, Object>> updateMutableDataTCSTask =
updateMutableDataTCS.getTask();

Map<String, Object> doTransactionMap = new HashMap<>();
final Map<String, Object> doTransactionMap = new HashMap<>();
doTransactionMap.put("transactionKey", arguments.get("transactionKey"));

final Map<String, Object> snapshotMap = new HashMap<>();
Expand All @@ -342,39 +345,46 @@ public Transaction.Result doTransaction(MutableData mutableData) {
doTransactionMap.put("snapshot", snapshotMap);

// Return snapshot to Dart side for update.
channel.invokeMethod(
"DoTransaction",
doTransactionMap,
new MethodChannel.Result() {
activity.runOnUiThread(
new Runnable() {
@Override
@SuppressWarnings("unchecked")
public void success(Object result) {
updateMutableDataTCS.setResult((Map<String, Object>) result);
}

@Override
public void error(
String errorCode, String errorMessage, Object errorDetails) {
String exceptionMessage =
"Error code: "
+ errorCode
+ "\nError message: "
+ errorMessage
+ "\nError details: "
+ errorDetails;
updateMutableDataTCS.setException(new Exception(exceptionMessage));
}

@Override
public void notImplemented() {
updateMutableDataTCS.setException(
new Exception("DoTransaction not implemented on Dart side."));
public void run() {
channel.invokeMethod(
"DoTransaction",
doTransactionMap,
new MethodChannel.Result() {
@Override
@SuppressWarnings("unchecked")
public void success(Object result) {
updateMutableDataTCS.setResult((Map<String, Object>) result);
}

@Override
public void error(
String errorCode, String errorMessage, Object errorDetails) {
String exceptionMessage =
"Error code: "
+ errorCode
+ "\nError message: "
+ errorMessage
+ "\nError details: "
+ errorDetails;
updateMutableDataTCS.setException(
new Exception(exceptionMessage));
}

@Override
public void notImplemented() {
updateMutableDataTCS.setException(
new Exception("DoTransaction not implemented on Dart side."));
}
});
}
});

try {
// Wait for updated snapshot from the Dart side.
Map<String, Object> updatedSnapshotMap =
final Map<String, Object> updatedSnapshotMap =
Tasks.await(
updateMutableDataTCSTask,
(int) arguments.get("transactionTimeout"),
Expand All @@ -394,7 +404,7 @@ public void notImplemented() {
@Override
public void onComplete(
DatabaseError databaseError, boolean committed, DataSnapshot dataSnapshot) {
Map<String, Object> completionMap = new HashMap<>();
final Map<String, Object> completionMap = new HashMap<>();
completionMap.put("transactionKey", arguments.get("transactionKey"));
if (databaseError != null) {
completionMap.put("error", asMap(databaseError));
Expand All @@ -408,7 +418,12 @@ public void onComplete(
}

// Invoke transaction completion on the Dart side.
result.success(completionMap);
activity.runOnUiThread(
new Runnable() {
public void run() {
result.success(completionMap);
}
});
}
});
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_database/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase Database, a cloud-hosted NoSQL database
with realtime data syncing across Android and iOS clients, and offline access.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_database
version: 3.0.3
version: 3.0.4

flutter:
plugin:
Expand Down