Код: Выделить всё
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');
}
}
Но я уже понял, что это проблема iOS SDK, но я надеюсь, что кто -то сможет мне как скорее, если я ошибся.
Подробнее здесь: https://stackoverflow.com/questions/797 ... nly-in-ios