datetime_loop 패키지는 시스템의 현재 날짜와 시간을 모니터링하고 설정 가능한 시간 간격(초, 분, 시 등)에 따라 재구성(rebuild)을 트리거하는 위젯을 제공하는 플러터 유틸리티입니다. 시계, 카운트다운, 실시간 데이터 표시와 같은 동적 시간 기반 콘텐츠가 필요한 UI에서 실시간 업데이트를 간편하게 처리합니다. 이 위젯은 불필요한 오버헤드 없이 시스템 시간 변경 사항을 효율적으로 감지하여 모든 플랫폼에서 부드러운 성능을 보장합니다. 시간 진행과 연결된 주기적인 갱신이 필요한 애플리케이션에 이상적입니다.
사용 사례
실시간 시계 표시
카운트다운 타이머
실시간 데이터 업데이트
시간 기반 UI 새로 고침
동적 콘텐츠 스케줄링
주요 기능
지정된 시간 간격에서 다시 빌드
효율적인 시스템 시간 리스닝
크로스 플랫폼 지원
사용자 정의 시간 단위
최소한의 성능 영향
적합한 대상
시간에 따라 달라지는 UI를 가진 앱
경량 시간 리스너가 필요한 개발자
자주 UI 업데이트가 필요한 프로젝트
시계 또는 타이머 애플리케이션
실시간 대시보드
고려 사항
간격이 너무 짧으면 과도한 재빌드를 유발할 수 있습니다
복잡한 위젯에서 상태를 신중하게 다뤄야 합니다
장시간 실행되는 백그라운드 작업에 적합하지 않음
불변 또는 경량 UI 컴포넌트와 함께 사용하는 것이 가장 좋습니다
UI 수준의 시간 모니터링에 제한됨
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
A Flutter package that provides a widget to listen to the system's datetime and trigger a rebuild based on the specified time unit
Support the project by giving the repo a ⭐ and showing some ❤️!
Usage
Import the package in your Dart code:
import'package:datetime_loop/datetime_loop.dart';
Using DateTimeLoopBuilder
Use the DateTimeLoopBuilder widget to rebuild UI elements based on system time updates. You can provide a timeUnit for simple setups or a custom DateTimeLoopController for advanced control (e.g., pause/resume):
The DateTimeLoopController provides a stream of datetime updates and supports advanced features like pausing and resuming updates, useful for optimizing resource usage (e.g., when the app is backgrounded):
final controller = DateTimeLoopController(timeUnit: TimeUnit.minutes);
controller.dateTimeStream.listen((dateTime) {
print('Current time: $dateTime');
});
// Pause updates to save resources
controller.pause();
// Resume updates with an immediate trigger
controller.resume(triggerImmediate: true);
// Use the controller with DateTimeLoopBuilderDateTimeLoopBuilder(
controller: controller,
builder: (context, dateTime, child) {
returnText('Time: ${dateTime.toString().split('.').first}');
},
);
// Dispose of the controller when done
controller.dispose();
Testing with getNow
Both DateTimeLoopBuilder and DateTimeLoopController support a getNow parameter that allows you to mock the system time. This is particularly useful for testing and simulating different time scenarios: