FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[cloud_firestore] Fixes crash on Android when run a transaction by hoc081098 · Pull Request #87 · firebase/flutterfire · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) .md  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.9+5

* Fixes a crash on Android when running a transaction without an internet connection.

## 0.12.9+4

* Fix integer conversion warnings on iOS.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ public void onMethodCall(MethodCall call, final Result result) {
final Map<String, Object> arguments = call.arguments();
getFirestore(arguments)
.runTransaction(
new Transaction.Function<Map<String, Object>>() {
new Transaction.Function<TransactionResult>() {
@Nullable
@Override
public Map<String, Object> apply(@NonNull Transaction transaction) {
public TransactionResult apply(@NonNull Transaction transaction) {
// Store transaction.
int transactionId = (Integer) arguments.get("transactionId");
transactions.append(transactionId, transaction);
Expand Down Expand Up @@ -424,23 +424,31 @@ public void notImplemented() {
Tasks.await(transactionTCSTask, timeout, TimeUnit.MILLISECONDS);

// Once transaction completes return the result to the Dart side.
return transactionResult;
return new TransactionResult(transactionResult);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
result.error("Error performing transaction", e.getMessage(), null);
return new TransactionResult(e);
}
return null;
}
})
.addOnCompleteListener(
new OnCompleteListener<Map<String, Object>>() {
new OnCompleteListener<TransactionResult>() {
@Override
public void onComplete(Task<Map<String, Object>> task) {
if (task.isSuccessful()) {
result.success(task.getResult());
} else {
public void onComplete(Task<TransactionResult> task) {
if (!task.isSuccessful()) {
result.error(
"Error performing transaction", task.getException().getMessage(), null);
return;
}

TransactionResult transactionResult = task.getResult();
if (transactionResult.exception == null) {
result.success(transactionResult.result);
} else {
result.error(
"Error performing transaction",
transactionResult.exception.getMessage(),
null);
}
}
});
Expand Down Expand Up @@ -820,6 +828,21 @@ public void onFailure(@NonNull Exception e) {
}
}
}

private static final class TransactionResult {
final @Nullable Map<String, Object> result;
final @Nullable Exception exception;

TransactionResult(@NonNull Exception exception) {
this.exception = exception;
this.result = null;
}

TransactionResult(@Nullable Map<String, Object> result) {
this.result = result;
this.exception = null;
}
}
}

final class FirestoreMessageCodec extends StandardMessageCodec {
Expand Down

Back | FazBrowse Home | New Git URL