mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-01-13 21:59:32 +00:00
Some checks are pending
Flutter CI & Release / Test (push) Waiting to run
Flutter CI & Release / Build Android APKs (push) Blocked by required conditions
Flutter CI & Release / build_linux (push) Blocked by required conditions
Flutter CI & Release / Create GitHub Release (push) Blocked by required conditions
24 lines
624 B
Dart
24 lines
624 B
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
void useInterval(VoidCallback callback, Duration delay) {
|
|
final savedCallback = useRef(callback);
|
|
savedCallback.value = callback;
|
|
|
|
useEffect(() {
|
|
final timer = Timer.periodic(delay, (_) => savedCallback.value());
|
|
return timer.cancel;
|
|
}, [delay]);
|
|
}
|
|
|
|
void useTimer(VoidCallback callback, Duration delay) {
|
|
final savedCallback = useRef(callback);
|
|
savedCallback.value = callback;
|
|
|
|
useEffect(() {
|
|
final timer = Timer(delay, savedCallback.value);
|
|
return timer.cancel;
|
|
}, [delay]);
|
|
}
|