패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.6.0

datetime_loop

시스템의 날짜 및 시간을 감지하고 지정된 시간 단위에 따라 다시 빌드를 트리거하는 위젯을 제공하는 플러터 패키지입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
274
좋아요
11
Pub 점수
160

패키지 설치

flutter pub add datetime_loop

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

datetime_loop 패키지는 시스템의 현재 날짜와 시간을 모니터링하고 설정 가능한 시간 간격(초, 분, 시 등)에 따라 재구성(rebuild)을 트리거하는 위젯을 제공하는 플러터 유틸리티입니다. 시계, 카운트다운, 실시간 데이터 표시와 같은 동적 시간 기반 콘텐츠가 필요한 UI에서 실시간 업데이트를 간편하게 처리합니다. 이 위젯은 불필요한 오버헤드 없이 시스템 시간 변경 사항을 효율적으로 감지하여 모든 플랫폼에서 부드러운 성능을 보장합니다. 시간 진행과 연결된 주기적인 갱신이 필요한 애플리케이션에 이상적입니다.

사용 사례

  • 실시간 시계 표시
  • 카운트다운 타이머
  • 실시간 데이터 업데이트
  • 시간 기반 UI 새로 고침
  • 동적 콘텐츠 스케줄링

주요 기능

  • 지정된 시간 간격에서 다시 빌드
  • 효율적인 시스템 시간 리스닝
  • 크로스 플랫폼 지원
  • 사용자 정의 시간 단위
  • 최소한의 성능 영향

적합한 대상

  • 시간에 따라 달라지는 UI를 가진 앱
  • 경량 시간 리스너가 필요한 개발자
  • 자주 UI 업데이트가 필요한 프로젝트
  • 시계 또는 타이머 애플리케이션
  • 실시간 대시보드

고려 사항

  • 간격이 너무 짧으면 과도한 재빌드를 유발할 수 있습니다
  • 복잡한 위젯에서 상태를 신중하게 다뤄야 합니다
  • 장시간 실행되는 백그라운드 작업에 적합하지 않음
  • 불변 또는 경량 UI 컴포넌트와 함께 사용하는 것이 가장 좋습니다
  • UI 수준의 시간 모니터링에 제한됨

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Clock Example

Buy Me A Coffee
Pub BSD 3-Clause License Pub
Pub likes Download Pub points

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):

DateTimeLoopBuilder(
  timeUnit: TimeUnit.seconds,
  builder: (context, dateTime, child) {
    return Column(
      children: [
        Container(
          width: 200,
          height: 200,
          color: Color((math.Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0),
        ),
        Text('$dateTime'),
      ],
    );
  }
)
Using DateTimeLoopController

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 DateTimeLoopBuilder
DateTimeLoopBuilder(
  controller: controller,
  builder: (context, dateTime, child) {
  return Text('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:

// Example: Testing with a mocked time
DateTime customTime = DateTime(2025, 10, 31, 12, 0, 0);

DateTimeLoopBuilder(
  timeUnit: TimeUnit.seconds,
  getNow: () => customTime,
  builder: (context, dateTime, child) {
    return Text('Mocked time: $dateTime');
  },
)

// Example: Using getNow with DateTimeLoopController
final controller = DateTimeLoopController(
  timeUnit: TimeUnit.minutes,
  getNow: () => customTime,
);

This feature enables:

  • Unit Testing: Write deterministic tests by controlling the datetime value
  • Time Simulation: Simulate different time scenarios without waiting for real time to pass
  • Debugging: Test edge cases and time-dependent behavior

You can check more examples of using this widget here

Issues and Feedback

Please file any issues or feedback here.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.