In order to retrieve any value from async function we can look at the following example of returning String value from Async function. This function returns token from firebase as String.
Future<String> getUserToken() async {
if (Platform.isIOS) checkforIosPermission();
await _firebaseMessaging.getToken().then((token) {
return token;
});
}
Fucntion to check for Ios permission
void checkforIosPermission() async{
await _firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
await _firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
}
Receiving the return value in function getToken
Future<void> getToken() async {
tokenId = await getUserToken();
}
print("token " + tokenId);