close
0

flutter run function every x amount of seconds

avatar
asked 13-09-2021

1 Answers


0

You need to move that code out of build() like

Timer? timer;

@override
void initState() {
  super.initState();
  timer = Timer.periodic(Duration(seconds: 15), (Timer t) => checkForNewSharedLists());
}

@override
void dispose() {
  timer?.cancel();
  super.dispose();
}
avatar
answered 13-09-2021