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; });
}
When call duration is over 5 second, the int score
increase by 1. With the code above, I am still getting two errors.
- Undefined name $
- The argument type 'int' can't be assigned to the parameter type 'Duration'.
I thought using $ didn't need defining and still confuse with what Duration should be assigned at. Any kind of help would be appreciated. Thanks in advance
CodePudding user response:
It’s not clear what you’re trying to achieve. As I read the code, you are trying to read a call log from the phone, and if duration is greater than 5 seconds you increment the score by 1, otherwise you reset it to 0? Is that correct?
It may be that your setState is not called from the right place, but it could also be that the duration of stopwatch.elapsed never reach 6 seconds.