Future<void> init() async {
if (!_initialized) {
_firebaseMessaging.requestNotificationPermissions();
User user = FirebaseAuth.instance.currentUser;
_uid = user.uid;
_firebaseMessaging.onTokenRefresh.listen((event) {
var db = FirebaseFirestore.instance;
var ref = FirebaseFirestore.instance.doc("users/$_uid");
db.runTransaction(
(transaction) => transaction.update(ref, {constants.fcm: event}));
});
I'm getting a return type error in this line:
db.runTransaction(
(transaction) => transaction.update(ref, {constants.fcm: event}));
The return type 'Transaction' isn't a 'Future<_>', as required by the closure's context
You're not returning anything from the method explicit, so Dart tries to return the result of the last line of code ( db.runTransaction
), which returns a Transaction
.
Since the method is marked to return Future<void>
, which is not the same as a Transaction
, you get the error you posted.
Why did you mark the method as returning a Future
? Does it really need to return anything? If so, what?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.