Closed TheHypnoo closed 2 years ago
@TheHypnoo
Can you provide flutter doctor -v
, pubpsec.yaml
and the error message in text format instead of in screenshots ?
Thanks.
@darshankawar Here is what you asked me:
ERROR IN TEXT:
════════ Exception caught by services library ══════════════════════════════════
The following PlatformException was thrown while de-activating platform stream on channel Usuarios/S51kvNax1YWMKS7ENGPicAsfSOi2/Reservas-[DEFAULT]-null-DatabaseEventType.value-[]#2:
PlatformException(error, No active stream to cancel, null, null)
When the exception was thrown, this was the stack
#0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:607
#1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:167
<asynchronous suspension>
#2 EventChannel.receiveBroadcastStream.<anonymous closure>
package:flutter/…/services/platform_channel.dart:518
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════
@TheHypnoo Can you also provide a complete minimal reproducible code sample that we can directly use to verify this behavior ?
@darshankawar For ease of use, maybe adding the database structure and the function I use which shows the error?
Future<List<String>> getNameDirections() async {
try {
final List<String> directions = await databaseReference
.child("Users")
.child(uid!)
.child("Bookings") // If you don't add an OrderBy .. () it won't work, it will show the error I show in the comment above
.once()
.then((response) {
final data = response.snapshot.children; // Return: (Instance of 'DataSnapshot', Instance of 'DataSnapshot')
if (data.isEmpty) return [];
final List<String> listDirections = [];
for (var element in data) {
final Map<dynamic, dynamic> data = element.value as Map;
listDirections.add(data["direccion"]);
}
return listDirections;
});
return directions;
} catch (e) {
return [];
}
}
Although it shows the error, the try catch does not perform its function I need to read each Reservation to be able to read the name of the address. It only happens to me with this call.
STRUCTURE DATABASE:
/
Users/
uidUser/
Bookings/
uidBooking/
direction: "Direction ..."
Verified this using the plugin example and using below code snippet:
void _queryWithOnce() async {
DataSnapshot snapshot = (await FirebaseDatabase.instance
.reference()
.child("messages")
.equalTo("message1")
.once()) as DataSnapshot;
if (snapshot.exists) {
print("Snap : ${snapshot.value}");
Map<String, dynamic> result = Map<String, dynamic>.from(snapshot.value);
result.forEach((key, value) {
_messageList.add(Map<String, dynamic>.from(value));
});
setState(() {});
}
}
With which, I get below exception:
PlatformException(error, No active stream to cancel, null, null)
When the exception was thrown, this was the stack
#0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:607
#1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:167
<asynchronous suspension>
#2 EventChannel.receiveBroadcastStream.<anonymous closure>
package:flutter/…/services/platform_channel.dart:518
<asynchronous suspension>
firebase_database: ^9.0.4
Hey @TheHypnoo, I used your initial code snippet and I found no problems. Looking at the stack trace, I would be inclined to think there is something unusual within the map returned from the database. Could you try with a Reservas
map that has a property with a simple string and see if that works at least?
@darshankawar, That is an outdated code snippet. Here it is updated which does not return an error for me:
DatabaseEvent event = await FirebaseDatabase.instance
.ref()
.child("messages")
.equalTo("message1")
.once();
if (event.snapshot.exists) {
print("Snap : ${event.snapshot.value}");
Map<String, dynamic> result = Map<String, dynamic>.from(event.snapshot.value as Map);
result.forEach((key, value) {
_messageList.add(Map<String, dynamic>.from(value));
});
setState(() {});
}
@russellwheatley & @darshankawar I think that after so much thinking and testing, I have realized the possible failure that causes it to show that error.
Can it happen that if you make two different calls to two "different" functions but to the same identical children, that error happens? Could someone check it out?
Can it happen that if you make two different calls to two "different" functions but to the same identical children, that error happens? Could someone check it out?
If you asking this scenario in context of .once()
method, then that function listens for exactly one event of the specified event type and then stops listening. If doing so, you may be getting the said exception.
So there was the problem. I used two functions where the children were the same, and was trying to listen twice.
Although before closing the issue, I have another question.
snapshot.children only performs the order to the root, but to the lower objects it does not order them. Example:
/
Users/
uidUser/
personal-information/
name: "Josh"
surname: "Smith"
phone/
t0: "+34 123456789"
t1: "+34 1234567812"
t2: "+34 123243243"
The phone data is not sorted, what would be the way to sort it from the root of that user?
what would be the way to sort it from the root of that user?
I guess this question is better suited for support channels like Stackoverflow, so please ask the same there. Closing this issue.
Bug report
Describe the bug This is a call to perform an once(), in this case if I don't add any orderBy ... (), it tells me this error I am using firebase database version ^9.0.4