flutter_countdown_timer 4.1.0 copy "flutter_countdown_timer: ^4.1.0" to clipboard
flutter_countdown_timer: ^4.1.0 copied to clipboard

A flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇

CountdownTimer #

A simple flutter countdown timer widget.Count down through the end timestamp,Trigger an event after the countdown ends.

Installing #

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_countdown_timer: ^4.1.0
copied to clipboard

Install it

$ flutter pub get
copied to clipboard

CountdownTimer #

name description
endWidget The widget displayed at the end of the countdown
widgetBuilder Widget Function(BuildContext context, CurrentRemainingTime time)
controller CountdownTimer start and dispose controller
endTime Countdown end time stamp
onEnd Countdown end event
textStyle Text color

CountdownTimerController #

name description
endTime Countdown end time stamp
onEnd Countdown end event

Example #

Simple to use #

int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

...
CountdownTimer(
  endTime: endTime,
),
copied to clipboard

Execute event at end. #

int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

void onEnd() {
  print('onEnd');
}

...
CountdownTimer(
  endTime: endTime,
  onEnd: onEnd,
),
copied to clipboard

Use the controller to end the countdown early. #

  CountdownTimerController controller;
  int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

  @override
  void initState() {
    super.initState();
    controller = CountdownTimerController(endTime: endTime, onEnd: onEnd);
  }

  void onEnd() {
    print('onEnd');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          CountdownTimer(
              controller: controller,
              onEnd: onEnd,
              endTime: endTime,
          ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.stop),
        onPressed: () {
          onEnd();
          controller.disposeTimer();
        },
      ),
    );
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
copied to clipboard

Custom style. #

  int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          CountdownTimer(
            endTime: endTime,
            widgetBuilder: (_, CurrentRemainingTime time) {
              if (time == null) {
                return Text('Game over');
              }
              return Text(
                  'days: [ ${time.days} ], hours: [ ${time.hours} ], min: [ ${time.min} ], sec: [ ${time.sec} ]');
            },
          ),
      ),
    );
  }
copied to clipboard

Using millisecond animation #

class _CountdownTimerPageState extends State

@override void initState() { super.initState(); controller = CountdownTimerController(endTime: endTime, onEnd: onEnd, vsync: this); }

@override Widget build(BuildContext context) { return Scaffold( body: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children:

}

### In ListView.builder
copied to clipboard

class ListViewPage extends StatefulWidget { static final String rName = "ListView";

@override _ListViewPageState createState() => _ListViewPageState(); }

class _ListViewPageState extends State

@override Widget build(BuildContext context) { return Scaffold( body: ListView.builder( itemCount: 200, itemBuilder: (context, index) { if (index == 0) { return _CountdownDemo(endTime); } else { return Container( height: 200, color: Colors.blue, margin: EdgeInsets.all(10), ); } }, ), ); } }

class _CountdownDemo extends StatefulWidget { final int endTime;

_CountdownDemo(this.endTime);

@override __CountdownDemoState createState() => __CountdownDemoState(); }

class __CountdownDemoState extends State<_CountdownDemo> { CountdownTimerController countdownTimerController;

@override Widget build(BuildContext context) { return CountdownTimer( controller: countdownTimerController, ); }

@override void initState() { super.initState(); countdownTimerController = CountdownTimerController(endTime: widget.endTime); } }

## Countdown
copied to clipboard

CountdownController countdownController = CountdownController(duration: Duration(minutes: 1));

Scaffold( body: Center( child: Countdown(countdownController: countdownController), ), floatingActionButton: FloatingActionButton( child: Icon(countdownController.isRunning ? Icons.stop : Icons.play_arrow), onPressed: () { if(!countdownController.isRunning) { ///start countdownController.start(); } else { ///pause countdownController.stop(); } setState(() { ///change icon }); }, ), )

![countdown.gif](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/countdown.gif)

![000.gif](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/001.gif)

![./example_2.png](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/example_2.jpg)
![/example_0.png](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/example_0.jpg)

![example_1.png](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/example_1.jpg)
![000.gif](https://github.com/wuweijian1997/FlutterCountdownTimer/blob/master/example/000.gif)

copied to clipboard
311
likes
130
points
23.5k
downloads

Publisher

unverified uploader

Weekly Downloads

2024.08.10 - 2025.02.22

A flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on flutter_countdown_timer