Skip to content

Commit

Permalink
[Cloud_firestore]add type params for invokeMethod calls. (firebase#1414)
Browse files Browse the repository at this point in the history
Bump min flutter version to 1.2.0.
Add template type parameter for invokeMethod calls.
Updated invokeMethod and invokeMethod to using invokeListMethod and invokeMapMethod if any.

flutter/flutter#26431
  • Loading branch information
Chris Yang authored Mar 29, 2019
1 parent 5b688c9 commit 9e56533
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 89 deletions.
5 changes: 5 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.7+2

* Bump the minimum Flutter version to 1.2.0.
* Add template type parameter to `invokeMethod` calls.

## 0.9.7+1

* Update README with example of getting a document.
Expand Down
31 changes: 7 additions & 24 deletions packages/cloud_firestore/lib/src/document_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class DocumentReference {
/// If [merge] is true, the provided data will be merged into an
/// existing document instead of overwriting.
Future<void> setData(Map<String, dynamic> data, {bool merge = false}) {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return Firestore.channel.invokeMethod(
return Firestore.channel.invokeMethod<void>(
'DocumentReference#setData',
<String, dynamic>{
'app': firestore.app.name,
Expand All @@ -61,10 +58,7 @@ class DocumentReference {
///
/// If no document exists yet, the update will fail.
Future<void> updateData(Map<String, dynamic> data) {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return Firestore.channel.invokeMethod(
return Firestore.channel.invokeMethod<void>(
'DocumentReference#updateData',
<String, dynamic>{
'app': firestore.app.name,
Expand All @@ -78,10 +72,8 @@ class DocumentReference {
///
/// If no document exists, the read will return null.
Future<DocumentSnapshot> get() async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await Firestore.channel.invokeMethod(
final Map<String, dynamic> data =
await Firestore.channel.invokeMapMethod<String, dynamic>(
'DocumentReference#get',
<String, dynamic>{'app': firestore.app.name, 'path': path},
);
Expand All @@ -94,10 +86,7 @@ class DocumentReference {

/// Deletes the document referred to by this [DocumentReference].
Future<void> delete() {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return Firestore.channel.invokeMethod(
return Firestore.channel.invokeMethod<void>(
'DocumentReference#delete',
<String, dynamic>{'app': firestore.app.name, 'path': path},
);
Expand All @@ -120,10 +109,7 @@ class DocumentReference {
StreamController<DocumentSnapshot> controller; // ignore: close_sinks
controller = StreamController<DocumentSnapshot>.broadcast(
onListen: () {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
_handle = Firestore.channel.invokeMethod(
_handle = Firestore.channel.invokeMethod<int>(
'Query#addDocumentListener',
<String, dynamic>{
'app': firestore.app.name,
Expand All @@ -136,10 +122,7 @@ class DocumentReference {
},
onCancel: () {
_handle.then((int handle) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await Firestore.channel.invokeMethod(
await Firestore.channel.invokeMethod<void>(
'Query#removeListener',
<String, dynamic>{'handle': handle},
);
Expand Down
21 changes: 7 additions & 14 deletions packages/cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,21 @@ class Firestore {
'Transaction timeout must be more than 0 milliseconds');
final int transactionId = _transactionHandlerId++;
_transactionHandlers[transactionId] = transactionHandler;
final Map<dynamic, dynamic> result = await channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('Firestore#runTransaction', <String, dynamic>{
final Map<String, dynamic> result = await channel
.invokeMapMethod<String, dynamic>(
'Firestore#runTransaction', <String, dynamic>{
'app': app.name,
'transactionId': transactionId,
'transactionTimeout': timeout.inMilliseconds
});
return result?.cast<String, dynamic>() ?? <String, dynamic>{};
return result ?? <String, dynamic>{};
}

@deprecated
Future<void> enablePersistence(bool enable) async {
assert(enable != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod('Firestore#enablePersistence', <String, dynamic>{
await channel
.invokeMethod<void>('Firestore#enablePersistence', <String, dynamic>{
'app': app.name,
'enable': enable,
});
Expand All @@ -139,10 +135,7 @@ class Firestore {
String host,
bool sslEnabled,
bool timestampsInSnapshotsEnabled}) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod('Firestore#settings', <String, dynamic>{
await channel.invokeMethod<void>('Firestore#settings', <String, dynamic>{
'app': app.name,
'persistenceEnabled': persistenceEnabled,
'host': host,
Expand Down
16 changes: 4 additions & 12 deletions packages/cloud_firestore/lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ class Query {
StreamController<QuerySnapshot> controller; // ignore: close_sinks
controller = StreamController<QuerySnapshot>.broadcast(
onListen: () {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
_handle = Firestore.channel.invokeMethod(
_handle = Firestore.channel.invokeMethod<int>(
'Query#addSnapshotListener',
<String, dynamic>{
'app': firestore.app.name,
Expand All @@ -70,10 +67,7 @@ class Query {
},
onCancel: () {
_handle.then((int handle) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await Firestore.channel.invokeMethod(
await Firestore.channel.invokeMethod<void>(
'Query#removeListener',
<String, dynamic>{'handle': handle},
);
Expand All @@ -86,10 +80,8 @@ class Query {

/// Fetch the documents for this query
Future<QuerySnapshot> getDocuments() async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await Firestore.channel.invokeMethod(
final Map<String, dynamic> data =
await Firestore.channel.invokeMapMethod<String, dynamic>(
'Query#getDocuments',
<String, dynamic>{
'app': firestore.app.name,
Expand Down
23 changes: 6 additions & 17 deletions packages/cloud_firestore/lib/src/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ class Transaction {
Firestore _firestore;

Future<DocumentSnapshot> get(DocumentReference documentReference) async {
final dynamic result = await Firestore.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('Transaction#get', <String, dynamic>{
final Map<String, dynamic> result = await Firestore.channel
.invokeMapMethod<String, dynamic>('Transaction#get', <String, dynamic>{
'app': _firestore.app.name,
'transactionId': _transactionId,
'path': documentReference.path,
Expand All @@ -33,10 +30,7 @@ class Transaction {

Future<void> delete(DocumentReference documentReference) async {
return Firestore.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('Transaction#delete', <String, dynamic>{
.invokeMethod<void>('Transaction#delete', <String, dynamic>{
'app': _firestore.app.name,
'transactionId': _transactionId,
'path': documentReference.path,
Expand All @@ -46,10 +40,7 @@ class Transaction {
Future<void> update(
DocumentReference documentReference, Map<String, dynamic> data) async {
return Firestore.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('Transaction#update', <String, dynamic>{
.invokeMethod<void>('Transaction#update', <String, dynamic>{
'app': _firestore.app.name,
'transactionId': _transactionId,
'path': documentReference.path,
Expand All @@ -59,10 +50,8 @@ class Transaction {

Future<void> set(
DocumentReference documentReference, Map<String, dynamic> data) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return Firestore.channel.invokeMethod('Transaction#set', <String, dynamic>{
return Firestore.channel
.invokeMethod<void>('Transaction#set', <String, dynamic>{
'app': _firestore.app.name,
'transactionId': _transactionId,
'path': documentReference.path,
Expand Down
25 changes: 5 additions & 20 deletions packages/cloud_firestore/lib/src/write_batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ part of cloud_firestore;
/// nor can it be committed again.
class WriteBatch {
WriteBatch._(this._firestore)
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
: _handle = Firestore.channel.invokeMethod(
: _handle = Firestore.channel.invokeMethod<dynamic>(
'WriteBatch#create', <String, dynamic>{'app': _firestore.app.name});

final Firestore _firestore;
Expand All @@ -32,10 +29,7 @@ class WriteBatch {
if (!_committed) {
_committed = true;
await Future.wait<dynamic>(_actions);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await Firestore.channel.invokeMethod(
await Firestore.channel.invokeMethod<void>(
'WriteBatch#commit', <String, dynamic>{'handle': await _handle});
} else {
throw StateError("This batch has already been committed.");
Expand All @@ -47,10 +41,7 @@ class WriteBatch {
if (!_committed) {
_handle.then((dynamic handle) {
_actions.add(
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
Firestore.channel.invokeMethod(
Firestore.channel.invokeMethod<void>(
'WriteBatch#delete',
<String, dynamic>{
'app': _firestore.app.name,
Expand All @@ -77,10 +68,7 @@ class WriteBatch {
if (!_committed) {
_handle.then((dynamic handle) {
_actions.add(
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
Firestore.channel.invokeMethod(
Firestore.channel.invokeMethod<void>(
'WriteBatch#setData',
<String, dynamic>{
'app': _firestore.app.name,
Expand All @@ -105,10 +93,7 @@ class WriteBatch {
if (!_committed) {
_handle.then((dynamic handle) {
_actions.add(
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
Firestore.channel.invokeMethod(
Firestore.channel.invokeMethod<void>(
'WriteBatch#updateData',
<String, dynamic>{
'app': _firestore.app.name,
Expand Down
4 changes: 2 additions & 2 deletions packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
version: 0.9.7+1
version: 0.9.7+2

flutter:
plugin:
Expand All @@ -27,4 +27,4 @@ dev_dependencies:

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=0.2.4 <2.0.0"
flutter: ">=1.2.0 <2.0.0"

0 comments on commit 9e56533

Please sign in to comment.