패키지, 저장소 및 앱 카테고리 검색

flutter_countdown_timer 표지
패키지 상세v4.1.0

flutter_countdown_timer

플러터 카운트다운 타이머입니다. [10일 5:30:46] ⬇⬇⬇⬇

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.8만
좋아요
315
Pub 점수
130

패키지 설치

flutter pub add flutter_countdown_timer

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

시간을 '10일 5:30:46'와 같은 형식으로 표시하는 사용자 정의 가능한 카운트다운 타이머 위젯을 제공하는 플러터 패키지입니다. 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 여러 플랫폼을 지원합니다. 경매, 퀴즈, 알림과 같은 시간 제한 이벤트가 필요한 앱에 적합합니다. 프로그래밍적으로 일시정지, 재시작 및 초기화할 수 있습니다. 플러터 UI 시스템과 원활하게 통합되며, 표시되는 시간에 대한 유연한 스타일링 옵션을 제공합니다.

사용 사례

  • 이벤트 카운트다운
  • 퀴즈 타이머
  • 경매 카운트다운
  • 리마인더 시스템
  • 게임 타이머

주요 기능

  • 사용자 지정 가능한 시간 형식
  • 일시정지/재개 기능
  • 크로스 플랫폼 지원
  • 스타일 옵션
  • 프로그래밍 제어

적합한 대상

  • 시간에 민감한 앱 기능
  • 인터랙티브 UI 컴포넌트
  • 교육 앱
  • 전자상거래 타이머

고려 사항

  • 타이머 만료에 대한 수동 처리가 필요합니다
  • 제한된 내장 애니메이션 효과
  • 시스템 알람과의 네이티브 통합 없음
  • 정확한 디바이스 시간에 의존
  • 매우 긴 기간에 최적화되지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

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

Install it

$ flutter pub get

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,
),
Execute event at end.
int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

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

...
CountdownTimer(
  endTime: endTime,
  onEnd: onEnd,
),
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();
  }
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} ]');
            },
          ),
      ),
    );
  }
Using millisecond animation
class _CountdownTimerPageState extends State<CountdownTimerPage>
    with SingleTickerProviderStateMixin {
  late CountdownTimerController controller;
  int endTime = DateTime.now().millisecondsSinceEpoch +
      Duration(seconds: 30).inMilliseconds;

  @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: <Widget>[
          CountdownTimer(
            controller: controller,
            widgetBuilder: (BuildContext context, CurrentRemainingTime? time) {
              if (time == null) {
                return Text('Game over');
              }
              List<Widget> list = [];
              if (time.sec != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_very_satisfied),
                    Text(time.sec.toString()),
                  ],
                ));
              }
              if (time.milliseconds != null) {
                list.add(Row(
                  children: <Widget>[
                    Icon(Icons.sentiment_very_satisfied),
                    AnimatedBuilder(
                      animation: time.milliseconds!,
                      builder: (context, child) {
                        return Text("${(time.milliseconds!.value * 1000).toInt()}");
                      },
                    )
                  ],
                ));
              }
              return Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: list,
              );
            },
          ),
        ],
      ),
    );
  }

}
In ListView.builder
class ListViewPage extends StatefulWidget {
  static final String rName = "ListView";

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

class _ListViewPageState extends State<ListViewPage> {
  int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 60 * 60;

  @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

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

000.gif

./example_2.png /example_0.png

example_1.png 000.gif

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트