パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.6.0

datetime_loop

システムの日時をリッスンし、指定された時間単位に基づいて再構築をトリガーするウィジェットを提供するFlutterパッケージ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
274
いいね数
11
Pub ポイント
160

パッケージをインストール

flutter pub add datetime_loop

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

datetime_loop パッケージは、Flutter のユーティリティであり、システムの現在日時を監視するウィジェットを提供し、秒、分、または時間などの設定可能な時間間隔に基づいて再構築をトリガーします。時計、カウントダウン、ライブデータ表示など、動的な時間ベースのコンテンツが必要な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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。