Skip to content

Commit 23c7ae3

Browse files
arashbimit-mit
authored andcommitted
Add update command to firebase_database (flutter#152)
* update command * Update command * Compile error fixed * dart formatting * reverting back to master version * Adding test case for update command * always specify types * attempting to fix travis * Small re-formatting * Small re-formatting
1 parent 4e8938a commit 23c7ae3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ public void onMethodCall(MethodCall call, final Result result) {
260260
break;
261261
}
262262

263+
case "DatabaseReference#update":
264+
{
265+
Map<String, Object> arguments = call.arguments();
266+
Map value = (Map) arguments.get("value");
267+
DatabaseReference reference = getReference(arguments);
268+
reference.updateChildren(value, new DefaultCompletionListener(result));
269+
break;
270+
}
271+
263272
case "DatabaseReference#setPriority":
264273
{
265274
Map<String, Object> arguments = call.arguments();

packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
184184
[getReference(call.arguments) setValue:call.arguments[@"value"]
185185
andPriority:call.arguments[@"priority"]
186186
withCompletionBlock:defaultCompletionBlock];
187+
} else if ([@"DatabaseReference#update" isEqualToString:call.method]) {
188+
[getReference(call.arguments) updateChildValues:call.arguments[@"value"]
189+
withCompletionBlock:defaultCompletionBlock];
187190
} else if ([@"DatabaseReference#setPriority" isEqualToString:call.method]) {
188191
[getReference(call.arguments) setPriority:call.arguments[@"priority"]
189192
withCompletionBlock:defaultCompletionBlock];

packages/firebase_database/lib/src/database_reference.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ class DatabaseReference extends Query {
7777
);
7878
}
7979

80+
/// Update the node with the `value`
81+
Future<Null> update(Map<String, dynamic> value) {
82+
return _database._channel.invokeMethod(
83+
'DatabaseReference#update',
84+
<String, dynamic>{'path': path, 'value': value},
85+
);
86+
}
87+
8088
/// Sets a priority for the data at this Firebase Database location.
8189
///
8290
/// Priorities can be used to provide a custom ordering for the children at a

packages/firebase_database/test/firebase_database_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ void main() {
117117
]),
118118
);
119119
});
120+
test('update', () async {
121+
final dynamic value = <String, dynamic>{'hello': 'world'};
122+
await database.reference().child("foo").update(value);
123+
expect(
124+
log,
125+
equals(<MethodCall>[
126+
new MethodCall(
127+
'DatabaseReference#update',
128+
<String, dynamic>{'path': 'foo', 'value': value},
129+
),
130+
]),
131+
);
132+
});
120133

121134
test('setPriority', () async {
122135
final int priority = 42;

0 commit comments

Comments
 (0)