A flutter countdown timer.

CountdownTimer

A simple flutter countdown timer component.

Installing

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

dependencies:
  flutter_countdown_timer: ^1.2.0

Install it

$ flutter pub get
name description
endTime Countdown end time stamp
onEnd Countdown end event
emptyWidget The widget displayed at the end of the countdown
daysSymbol final Widget daysSymbol
hoursSymbol final Widget hoursSymbol
minSymbol final Widget minSymbol
secSymbol final Widget secSymbol
textStyle final TextStyle textStyle
widgetBuilder Widget Function(BuildContext context, CurrentRemainingTime time)

Example

Now in your Dart code, you can use:

@override
  Widget build(BuildContext context) {
    int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 60 * 60;
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          CountdownTimer(
            endTime: endTime,
          ),
          CountdownTimer(
            endTime: endTime,
            textStyle: TextStyle(fontSize: 30, color: Colors.pink),
          ),
          CountdownTimer(
            endTime: endTime,
            widgetBuilder: (_, CurrentRemainingTime time) {
              return Text(
                  'days: [ ${time.days} ], hours: [ ${time.hours} ], min: [ ${time.min} ], sec: [ ${time.sec} ]');
            },
          ),
          CountdownTimer(
            endTime: endTime,
            widgetBuilder: (BuildContext context, CurrentRemainingTime time) {
              List<Widget> list = [];
              if(time.days != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_dissatisfied),
                    Text(time.days.toString()),
                  ],
                ));
              }
              if(time.hours != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_satisfied),
                    Text(time.hours.toString()),
                  ],
                ));
              }
              if(time.min != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_very_dissatisfied),
                    Text(time.min.toString()),
                  ],
                ));
              }
              if(time.sec != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_very_satisfied),
                    Text(time.sec.toString()),
                  ],
                ));
              }

              return Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: list,
              );
            },
          ),
        ],
      ),
    );
  }

./example_2.png /example_0.png

example_1.png 000.gif

Download Details:

Author: wuweijian1997

Source Code: https://github.com/wuweijian1997/FlutterCountdownTimer

#flutter #dart #mobile-apps

A flutter countdown timer.
30.25 GEEK