CountDownManager class
倒计时管理器(单例)
用于管理多个倒计时实例,支持同时运行多个倒计时,每个倒计时可以设置不同的时长和显示格式。
使用示例:
class GlobalCoundDown {
static final GlobalCoundDown _instance = GlobalCoundDown._internal();
static GlobalCoundDown get instance => _instance;
factory GlobalCoundDown() => _instance;
GlobalCoundDown._internal();
final countDownManager = CountDownManager();
var homeGiftCountDownId = 'homeGiftCountDown';
var homeGiftCountDownStr = '00:00'.obs;
var homeGiftCountDownMaxTime = 10 * 60;
void startHomeGiftCountDown() {
countDownManager.createCountDown(
id: homeGiftCountDownId,
maxSeconds: homeGiftCountDownMaxTime,
format: CountDownFormat.mmss,
onUpdate: (timeStr) {
homeGiftCountDownStr.value = timeStr;
},
onComplete: () {
homeGiftCountDownStr.value = '00:00';
countDownManager.disposeCountDown(homeGiftCountDownId);
},
);
countDownManager.startCountDown(homeGiftCountDownId);
}
}
Constructors
- CountDownManager()
-
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createCountDown(
{required String id, required int maxSeconds, required CountDownFormat format, required void onUpdate(String timeStr), void onComplete()?}) → String - 创建倒计时实例
-
disposeAll(
) → void - 销毁所有倒计时实例
-
disposeCountDown(
String id) → void - 销毁倒计时实例
-
getCountDown(
String id) → CountDownInstance? - 获取倒计时实例
-
getRemainingSeconds(
String id) → int? - 获取剩余时间(秒)
-
isCountDownRunning(
String id) → bool - 检查倒计时是否正在运行
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pauseCountDown(
String id) → void - 暂停倒计时
-
resetCountDown(
String id, {int? newMaxSeconds}) → void - 重置倒计时
-
resumeCountDown(
String id) → void - 恢复倒计时
-
startCountDown(
String id) → void - 启动倒计时
-
stopCountDown(
String id) → void - 停止倒计时
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited