scheduled_timer 1.0.0 copy "scheduled_timer: ^1.0.0" to clipboard
scheduled_timer: ^1.0.0 copied to clipboard

outdated

A simple timer that can be scheduled to run at a specific time, and will restore it's scheduled time across app restarts.

example/main.dart

import 'package:scheduled_timer/scheduled_timer.dart';



void main() async {

  /// Example 1
  /// One-off execution after 10 minutes (or more).
  ///
  /// If the app is stopped, and restarted again within 10 minutes, the scheduled time will be
  /// automatically retrieved and the function executed as scheduled.
  ///
  /// If the app is stopped, and restarted again after more than 10 minutes, `onMissedSchedule` will
  /// be executed immediately - which will in turn execute `onExecute`.
  ScheduledTimer example1;
  example1 = ScheduledTimer(
    id: 'example1',
    onExecute: (){
      print('Executing example1');
    },
    defaultScheduledTime: DateTime.now().add(Duration(minutes: 10)),
    onMissedSchedule: (){
      example1.execute();
    }
  );



  /// Example 2
  /// Periodic execution every 10 minutes (or more).
  ///
  /// We're scheduling a new execution after 10 minutes every time the timer executes, which will
  /// create a "periodic" timer.
  ///
  /// If the app is stopped, and restarted again within 10 minutes, the scheduled time will be
  /// automatically retrieved and the function executed as scheduled.
  ///
  /// If the app is stopped, and restarted again after more than 10 minutes, `onMissedSchedule` will
  /// be executed immediately - which will in turn execute `onExecute`.
  ScheduledTimer example2;
  example2 = ScheduledTimer(
    id: 'example2',
    onExecute: (){
      print('Executing example2');

      // Schedule the next execution 10 minutes from now. This will create a "periodic" timer,
      // which will self-execute every 10 minutes.
      example2.schedule(DateTime.now().add(Duration(minutes: 10)));
    },
    defaultScheduledTime: DateTime.now(),
    onMissedSchedule: (){
      example2.execute();
    }
  );

}
16
likes
40
points
746
downloads

Publisher

verified publishermagnuswikhog.com

Weekly Downloads

A simple timer that can be scheduled to run at a specific time, and will restore it's scheduled time across app restarts.

Repository (GitHub)

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on scheduled_timer