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

Commit 8d0df85

Browse files
committed
comments
1 parent bb4fdff commit 8d0df85

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

packages/firebase_storage/android/src/main/java/io/flutter/plugins/firebase/storage/FirebaseStoragePlugin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ public void onFailure(@NonNull Exception e) {
8585
});
8686
}
8787

88-
8988
private void updateMetadata(MethodCall call, final Result result) {
9089
String path = call.argument("path");
9190
Map<String, Object> metadata = call.argument("metadata");
9291
StorageReference ref = firebaseStorage.getReference().child(path);
9392
ref.updateMetadata(buildMetadataFromMap(metadata))
94-
.addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
95-
@Override
96-
public void onSuccess(StorageMetadata storageMetadata) {
97-
result.success(buildMapFromMetadata(storageMetadata));
98-
}
99-
})
93+
.addOnSuccessListener(
94+
new OnSuccessListener<StorageMetadata>() {
95+
@Override
96+
public void onSuccess(StorageMetadata storageMetadata) {
97+
result.success(buildMapFromMetadata(storageMetadata));
98+
}
99+
})
100100
.addOnFailureListener(new OnFailureListener() {
101101
@Override
102102
public void onFailure(@NonNull Exception e) {
@@ -198,7 +198,7 @@ private Map<String, Object> buildMapFromMetadata(StorageMetadata storageMetadata
198198
map.put("contentEncoding", storageMetadata.getContentEncoding());
199199
map.put("contentLanguage", storageMetadata.getContentLanguage());
200200
map.put("contentType", storageMetadata.getContentType());
201-
return map;
201+
return map;
202202
}
203203

204204
private void getData(MethodCall call, final Result result) {

packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ - (FIRStorageMetadata *)buildMetadataFromDictionary:(NSDictionary *)dictionary {
9595
return metadata;
9696
}
9797

98-
- (NSDictionary *)buildDictionaryFromMetadata:(FIRStorageMetadata *) metadata {
98+
- (NSDictionary *)buildDictionaryFromMetadata:(FIRStorageMetadata *)metadata {
9999
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
100100
[dictionary setValue:[metadata bucket] forKey:@"bucket"];
101101
[dictionary setValue:[NSString stringWithFormat:@"%lld", [metadata generation]]
@@ -157,12 +157,12 @@ - (void)updateMetadata:(FlutterMethodCall *)call result:(FlutterResult)result {
157157
FIRStorageReference *ref = [[FIRStorage storage].reference child:path];
158158
[ref updateMetadata:[self buildMetadataFromDictionary:metadataDictionary]
159159
completion:^(FIRStorageMetadata *metadata, NSError *error) {
160-
if (error != nil) {
161-
result(error.flutterError);
162-
} else {
163-
result([self buildDictionaryFromMetadata:metadata]);
164-
}
165-
}];
160+
if (error != nil) {
161+
result(error.flutterError);
162+
} else {
163+
result([self buildDictionaryFromMetadata:metadata]);
164+
}
165+
}];
166166
}
167167

168168
- (void)getDownloadUrl:(FlutterMethodCall *)call result:(FlutterResult)result {

packages/firebase_storage/lib/firebase_storage.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class StorageReference {
7070
}
7171

7272
/// Updates the metadata associated with this [StorageReference].
73+
///
74+
/// Returns a [Future] that will complete to the updated [StorageMetadata].
7375
Future<StorageMetadata> updateMetadata(StorageMetadata metadata) async {
7476
return new StorageMetadata._fromMap(await FirebaseStorage.channel
7577
.invokeMethod("StorageReference#updateMetadata", <String, dynamic>{

packages/firebase_storage/test/firebase_storage_test.dart

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ void main() {
8686
});
8787
});
8888

89-
9089
group('updateMetadata', () {
9190
final List<MethodCall> log = <MethodCall>[];
9291

@@ -96,7 +95,21 @@ void main() {
9695
FirebaseStorage.channel
9796
.setMockMethodCallHandler((MethodCall methodCall) async {
9897
log.add(methodCall);
99-
return <String, String>{'name': 'image.jpg'};
98+
switch (methodCall.method) {
99+
case 'StorageReference#getMetadata':
100+
return <String, String>{
101+
'name': 'image.jpg',
102+
};
103+
break;
104+
case 'StorageReference#updateMetadata':
105+
return <String, String>{
106+
'name': 'image.jpg',
107+
'contentLanguage': 'en'
108+
};
109+
break;
110+
default:
111+
break;
112+
}
100113
});
101114
ref = FirebaseStorage.instance
102115
.ref()
@@ -106,24 +119,33 @@ void main() {
106119
});
107120

108121
test('invokes correct method', () async {
109-
await ref.getMetadata();
122+
await ref.updateMetadata(const StorageMetadata(contentLanguage: 'en'));
110123

111124
expect(log, <Matcher>[
112125
isMethodCall(
113126
'StorageReference#updateMetadata',
114127
arguments: <String, dynamic>{
115128
'path': 'avatars/large/image.jpg',
129+
'metadata': <String, String>{
130+
'cacheControl': null,
131+
'contentDisposition': null,
132+
'contentLanguage': 'en',
133+
'contentType': null,
134+
'contentEncoding': null
135+
},
116136
},
117137
),
118138
]);
119139
});
120140

121141
test('returns correct result', () async {
122-
expect((await ref.getMetadata()).name, 'image.jpg');
142+
expect((await ref.getMetadata()).contentLanguage, null);
143+
expect((await ref.updateMetadata(
144+
const StorageMetadata(contentLanguage: 'en'))).contentLanguage,
145+
'en');
123146
});
124147
});
125148

126-
127149
group('getDownloadUrl', () {
128150
final List<MethodCall> log = <MethodCall>[];
129151

0 commit comments

Comments
 (0)