Open BuyMyBeard opened 5 hours ago
I was wrong on my initial conclusion. The issue has to do with _path not finding any matches in the storedDataMap if the child path doesn't contain a base '/'.
const fileUrl = 'path/file';
final fakeStorage = MockFirebaseStorage();
final localImage = await rootBundle.load('assets/images/devxpress-logo.png');
// Will set the data at /path/file in the storedDataMap
await fakeStorage.ref().child(fileUrl).putData(localImage.buffer.asUint8List(), SettableMetadata(contentType: 'image/png'));
// ...
// Will try to retrieve data at path/file in the storedDataMap. No results will be found
final response = ref.watch(storageProvider).ref(fileUrl).getMetadata();
Followup: If I try to get metadata by providing a path without a starting slash, It will match _path without the /
, but if I provide it, it will look for a path starting with //
, which doesn't make any sense.
I found the source of the issue. I was misusing the storage ref by providing it the url of the path. This is weird, because it was working fine using the real firebase storage, but wouldn't work correctly with firebase_storage_mocks.
If you upload a string or byte data to the fake storage, trying to retrieve the metadata will always fail at this null assertion:
https://github.com/atn832/firebase_storage_mocks/blob/871acd02519703c2822b205bc4ea6cf6981dc899/lib/src/mock_storage_reference.dart#L155-L156
Easy fix is to count the number of bytes in the data or string, and set it as the size.