flutter - 未来' 不是 '(() => dynamic) 类型的子类型?
问题描述
当我尝试延迟保存令牌设备的方法时出现此错误。
final pushnoti = new PushNoti();
pushnoti.configurePushNoti(context);
Future.delayed(Duration(seconds: 3), pushnoti.saveTokenDevice(currentUid));
return StreamBuilder<UserData>()
这是方法定义:
saveTokenDevice(String currentUid) async {
tokenDevice = await _firebaseMessaging.getToken();
if (tokenDevice != null) {
var tokenRef = _database
.collection(user_database)
.document(currentUid);
if (tokenRef != null){
await tokenRef.updateData({
'TokenDevice': FieldValue.arrayUnion([tokenDevice])
}
);
}
else {
}
}
我想做的是在创建用户后延迟该方法。
解决方案
Thewdelayed
构造函数需要一个返回值或 a 的函数Future
,但您编写代码的方式是saveTokenDevice
函数的结果,即 a Future
。应该是这样的:
Future.delayed(Duration(seconds: 3), () => pushnoti.saveTokenDevice(currentUid));
来源:https ://api.dart.dev/stable/2.10.1/dart-async/Future/Future.delayed.html
推荐阅读
- assembly - 这个汇编代码有问题吗?
- python - 保存多个洗牌的 csv 文件
- google-api - 使用 google Sheets API 获取列的元数据
- python - Pandas:如何将列中的字典列表映射为新行
- html - 为什么在 safari div 内的框内滚动溢出-y 折叠?
- android-layout - 更新目标 Android 版本更改布局
- mysql - SQL select from 1 x N where all大于
- button - 按钮冻结
- flutter - SingleSChildScrollView 在 IOS 中向上移动
- python - 未定义符号:cblas_dtrsm