I’m having a problem with my Flutter SDK code where when I call the function to fetch data from the databaseReference it returns all the data from my database (8950 items), even though I’m doing the correct filter. But this problem only happens in the iOS debug on Android and it’s returning only 1 exact item from the search.
DatabaseReference Function(String id) get productByIdRef =>
(String id) => _database.ref('products/$id');
StreamSubscription? _productsSubscription;
Future getProductInScanner(String id) async {
final cleanId = id.trim();
final snapshot = await productByIdRef(cleanId).get();
if (!snapshot.exists) {
return ProductData(
id: "",
brands: "",
composition: "",
country: "",
name: "",
urlImage: "",
);
}
final barcode = snapshot.key;
final val = snapshot.value;
try {
Map map = {};
if (val! is Map) {
return ProductData(
id: "",
brands: "",
composition: "",
country: "",
name: "",
urlImage: "",
);
}
if (val is Map) {
map = {...Map.from(val)};
}
Map filtered = {};
if (map.length > 1) {
filtered = Map.fromEntries(
map.entries
.where((e) => e.key == id.trim())
.map((e) => MapEntry(e.key, Map.from(e.value))),
);
}
if (filtered.isEmpty) {
return ProductData(
id: "",
brands: "",
composition: "",
country: "",
name: "",
urlImage: "",
);
}
return ProductData.fromMap(map);
} catch (_) {
throw FormatException('Erro ao fomatar dados do produto');
}
}
I need this code on iOS to return only the specific ID I’m specifying in .child().
But I’ve already realized it’s an iOS SDK issue, but I hope someone can help me as soon as possible if I’m mistaken.