Skip to content

An extremely easy-to-use flutter plugin that allows you to listen time changes.

License

Notifications You must be signed in to change notification settings

kaczmarzk/time_listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

time_listener

pub package

An extremely easy-to-use flutter plugin that allows you to listen time changes.

Features

This package makes very easy to listen time changes using a stream. The code responsible for checking time diff is run in an isolate, so you don't have to worry about performance.

Usage

To start listening create instance of the class and call "listen" method on it. Stream event with the new date will come every second.

  // actively listen for time updates with the interval specified in parameter
  // until listener.cancel() is called
  final listener = TimeListener()..listen((DateTime dt) {
  print('${dt.hour}:${dt.minute}:${dt.second}');
  });

  // don't forget to cancel listener when it is no longer needed
  // so the program doesn't run forever
  await listener.cancel();

To specify interval (by default every minute) you can use custom factory.

  // below code will emit new DateTime every minute without seconds precision
  // output - 21:37:00
  final listener = TimeListener()..listen((DateTime dt) {
  print('${dt.hour}:${dt.minute}:${dt.second}');
  });

  // but if you need u can specify more precise interval with custom factory
  // output - 21:37:24
  final listener = TimeListener.create(interval: CheckInterval.seconds)..listen((DateTime dt) {
  print('${dt.hour}:${dt.minute}:${dt.second}');
  });

About

An extremely easy-to-use flutter plugin that allows you to listen time changes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published