June 2017
Intermediate to advanced
873 pages
18h 9m
English
Let's suppose your code needs to run a certain function periodically at a certain interval. This recipe shows how you can do this very easily.
Look at the following code of recurring_function.dart:
import'dart:async';
var count = 0;
const TIMEOUT = const Duration(seconds: 5);
const MS = const Duration(milliseconds: 1);
void main() {
// 1. Running a function repeatedly:
const PERIOD = const Duration(seconds:2);
newTimer.periodic(PERIOD, repeatMe);
// 3. Running a function once after some time:
const AFTER70MS = const Duration(milliseconds:70);
new Timer(AFTER70MS, () => print('this was quick!'));
// 4. Running a function asap:
Timer.run(() => print('I ran asap!')); // 5. Calculating a period and provoking ...Read now
Unlock full access