CountDownWidget constructor

const CountDownWidget({
  1. Key? key,
  2. required Duration duration,
  3. required BuildWidgetByDuration builder,
  4. Duration stepDuration = const Duration(seconds: 1),
  5. OnControllerReady? onControllerReady,
  6. VoidCallback? onExpired,
  7. VoidCallback? onFinish,
  8. ValueChanged<Duration>? onDurationRemainChanged,
  9. Duration durationExpired = const Duration(),
  10. bool runWhenSleep = true,
  11. bool autoStart = true,
})

builder is function callback return Widget by durationRemain, it will be called when durationRemain Changed

onControllerReady is function callback, it will be called when CountDownTimerController is ready to use

onExpired it will be called when duration is less than or equal to durationExpired

onFinish it will be called when countdown finish

onDurationRemainChanged it will be called when duration changed

durationExpired is duration to check when countdown reach to timeExpire, default is 0

ex: if you want to set time expire when countdown to 00:30, set durationExpired = Duration(seconds: 30)

duration is total time you want to countdown, ex: you want countdown from 01:20 -> 00:00 set duration = Duration(seconds: 120)

stepDuration is the duration of step count, default is 1 second

runWhenSleep default is true

-- if true: onDurationRemainChanged will be called even when the phone turns off the screen

-- if false: onDurationRemainChanged will not be called when the phone turns off the screen

Note, whether you set runWhenSleep to true or false, when the app is reopened, the timer will still count the amount of time you turn off the screen, but it won't count if you call the controller.pause function.

Implementation

const CountDownWidget({
  Key? key,
  required this.duration,
  required this.builder,
  this.stepDuration = const Duration(seconds: 1),
  this.onControllerReady,
  this.onExpired,
  this.onFinish,
  this.onDurationRemainChanged,
  this.durationExpired = const Duration(),
  this.runWhenSleep = true,
  this.autoStart = true,
}) : super(key: key);