mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 03:46:47 +01:00
19 lines
458 B
Dart
19 lines
458 B
Dart
|
import 'dart:async';
|
||
|
import 'dart:ui';
|
||
|
|
||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||
|
|
||
|
// https://github.com/rrousselGit/flutter_hooks/issues/233#issuecomment-840416638
|
||
|
void useInterval(Duration delay, VoidCallback callback) {
|
||
|
final savedCallback = useRef(callback);
|
||
|
savedCallback.value = callback;
|
||
|
|
||
|
useEffect(
|
||
|
() {
|
||
|
final timer = Timer.periodic(delay, (_) => savedCallback.value());
|
||
|
return timer.cancel;
|
||
|
},
|
||
|
[delay],
|
||
|
);
|
||
|
}
|