未定义的 $ 和 Duration 参数类型
undefined $ and Duration parameter type
int score = 0;
Duration duration = Duration(seconds: Duration.secondsPerDay);
void callLogs() async {
Stopwatch stopwatch = new Stopwatch()..start();
Iterable<CallLogEntry> entries = await CallLog.get();
for (var item in entries) {
duration = ${stopwatch.elapsed;};
print('Duration ${stopwatch.elapsed}');
}
setState(() { duration > 5 ? score += 1 : score = 0; });
}
当通话时间超过5秒时,int score
增加1。使用上面的代码,我仍然得到两个错误。
- 未定义名称 $
- 无法将参数类型 'int' 分配给参数类型 'Duration'。
我认为使用 $ 不需要定义并且仍然混淆应该分配的 Duration。任何形式的帮助将不胜感激。提前致谢
不清楚您要实现的目标。当我阅读代码时,您正在尝试从 phone 读取通话记录,如果持续时间大于 5 秒,则将分数增加 1,否则将其重置为 0?对吗?
可能是你的 setState 没有从正确的地方调用,但也可能是 stopwatch.elapsed 的持续时间从未达到 6 秒。
int score = 0;
Duration duration = Duration(seconds: Duration.secondsPerDay);
void callLogs() async {
Stopwatch stopwatch = new Stopwatch()..start();
Iterable<CallLogEntry> entries = await CallLog.get();
for (var item in entries) {
duration = ${stopwatch.elapsed;};
print('Duration ${stopwatch.elapsed}');
}
setState(() { duration > 5 ? score += 1 : score = 0; });
}
当通话时间超过5秒时,int score
增加1。使用上面的代码,我仍然得到两个错误。
- 未定义名称 $
- 无法将参数类型 'int' 分配给参数类型 'Duration'。
我认为使用 $ 不需要定义并且仍然混淆应该分配的 Duration。任何形式的帮助将不胜感激。提前致谢
不清楚您要实现的目标。当我阅读代码时,您正在尝试从 phone 读取通话记录,如果持续时间大于 5 秒,则将分数增加 1,否则将其重置为 0?对吗?
可能是你的 setState 没有从正确的地方调用,但也可能是 stopwatch.elapsed 的持续时间从未达到 6 秒。