搜尋套件、儲存庫與 APP 分類

simple_timer 封面
套件詳情v2.0.0

simple_timer

一個簡單的計時器小部件,可顯示計時器進度並具有各種可自定義選項。

近 30 天下載
69
喜歡數
55
Pub 分數
70

安裝套件

flutter pub add simple_timer

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供簡單且可自訂的計時器元件,用於顯示倒數計時或秒錶進度。支援多種視覺與功能自訂,例如文字樣式、顏色和動畫選項。非常適合需要即時時間追蹤且設定簡單的應用程式。此元件輕量級,容易整合至現有的 UI 中。它能在跨平台環境中順暢運作,無需額外設定。

適用情境

  • 健身應用中的倒計時計時器
  • 生產力工具中的計時器功能
  • 計時器在教育測驗中顯示
  • 遊戲中的即時進度指示器
  • 基於時間的任務提醒

主要特色

  • 可自定義的計時器外觀
  • 平滑的進度動畫
  • 支援倒數計時與秒表模式
  • 與 Flutter 小部件的輕鬆整合
  • 可設定的文字與顏色主題

適合對象

  • 開發時間追蹤功能的開發者
  • UI 設計師需要乾淨的計時器組件
  • 需要最小計時器複雜度的應用程式
  • 初學者Flutter開發者學習狀態管理

使用建議

  • 僅限基本計時器功能
  • 沒有內建的持續計時器持久化支援
  • 不支援多個並行計時器
  • 平台特定的行為可能有所差異
  • 需要手動處理計時器生命週期

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

SimpleTimer

A Simple Timer Widget that displays the timer progress with various customizable options.

Installing

To Start using this library include simple_timer as a dependency in your puspec.yaml file. Make sure to include the latest version.

Pub link: https://pub.dev/packages/simple_timer

Usage

To use the widget, import the package in your project

import 'package:simple_timer/simple_timer.dart';

The timer can be controlled in two ways:

  • Using a TimerController (preferred) - The TimerController is a convenience wrapper (subclass) of an AnimationController and needs a TickerProvider, so be sure to extend a TickerProvider in your class. Declare and instantiate your timer controller like below:

    // declaration
    TimerController _timerController;
    
    // instantiation
    _timerController = TimerController(this);
    

    Note: Remember to dispose the TimerController

    and set the controller property to the TimerController object like below:

    Container(
        child: SimpleTimer(
            controller: _timerController,
            duration: Duration(seconds: 10),
        )
    )
    

    TimerController methods:

    Method Description
    start Starts the timer e.g. (_timerController.start())
    pause Pauses the timer e.g. (_timerController.pause())
    reset Resets the timer e.g. (_timerController.reset())
    restart Restarts the timer e.g. (_timerController.restart())
    add Increases time left by the specified duration i.e. allows more time e.g. (_timerController.add(Duration(seconds: 10)))
    subtract Decreases time left by the specified duration i.e. reduces the time e.g. (_timerController.subtract(Duration(seconds: 10)))
  • Setting the Status - The timer can also be controler by passing a TimerStatus value to the status property; like below:

    Container(
        child: SimpleTimer(
            status: TimerStatus.start,
            duration: Duration(seconds: 10),
        )
    )
    

Note: The SimpleTimer widget uses its parent size.

Customizable Options

There are various customizable options provided by the SimpleTimer widget, see below:

Property Description Value Type Default Value
duration The duration of the timer Duration
controller A TimerController to control the timer. If this is provided then status must be null. TimerController
status An alternative to the controller that sets the status of the timer. If provided, controller must be null TimerStatus
timerStyle Sets the look of the animated timer widget TimerStyle ring
delay Sets a start delay for timer - i.e. delays the start of the timer by the specified duration Duration Duration(seconds: 0)
backgroundColor The background color of the inner shape (circle) of the timer Color grey
progressIndicatorColor The color of the animating progress indicator. Color green
progressIndicatorDirection The rotating direction of the timer's progress indicator TimerProgressIndicatorDirection clockwise
displayProgressIndicator Sets whether to show the progress indicator bool true
displayProgressText Sets whether to show the progress text bool true
progressTextStyle The TextStyle used by the progress text. TextStyle
progressTextCountDirection The counting direction of the text displayed by the timer TimerProgressTextCountDirection count_down
progressTextFormatter A callback function to format the text displayed by this Timer. String Function(Duration) displays duration in MM:SS format
onStart Callback executed when the timer starts counting VoidCallback
onEnd Callback executed when the timer has finished counting VoidCallback
valueListener The callback executed for each change in the time elapsed void Function(Duration)

Pub link: https://pub.dev/packages/simple_timer

Demo - Controlling the Timer Status

simple_timer_demo_01

Demo - Customizable options

simple_timer_demo_02

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。