I am trying to understand the usage of async and await in Dart. Somehow I am having issues returning values in certain methods.
Consider the code below
Future<int> getMrn() async {
var mrnRef = await firebaseClient.child('mrn');
DataSnapshot ss;
StreamSubscription<Event> onValueSubscription = await mrnRef.onValue
.listen((event) {
ss = event.snapshot;
return ss.val();
});
//return Future<int> ss.val();
}
mrn
is of type int
which should be returned by getMrn
method. However each time the returned ss.val()
returns null
. It seems that ss = event.snapshot
is not seen in the last returned value
What is the correct way of doing this. Thanks