使用 flutter 进度条组件和 RotatedBox 旋转组件,实现时间流失进度条
进度条组件LinearProgressIndicator
属性说明:
value 0-1 之间 进度
RotatedBox 组件
quarterTurns 属性表示象限
quarterTurns: 0 水平
quarterTurns: 1 顺时针旋转 90 度(quarterTurns = 1)
quarterTurns: -1 逆时针旋转 90 度(quarterTurns = -1)。
代码实现
library flutter_timer_countdown;
import 'dart:async';
import 'package:LS/common/global.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
enum CountDownTimerFormat {
daysHoursMinutesSeconds,
daysHoursMinutes,
daysHours,
daysOnly,
hoursMinutesSeconds,
hoursMinutes,
hoursOnly,
minutesSeconds,
minutesOnly,
secondsOnly,
}
typedef OnTickCallBack = void Function(Duration remainingTime);
class TimerCountdown extends StatefulWidget {
/// Format for the timer coundtown, choose between different `CountDownTimerFormat`s
final CountDownTimerFormat format;
/// Defines the time when the timer is over.
final DateTime endTime;
/// Gives you remaining time after every tick.
final OnTickCallBack? onTick;
/// Function to call when the timer is over.
final VoidCallback? onEnd;
/// Toggle time units descriptions.
final bool enableDescriptions;
/// `TextStyle` for the time numbers.
final TextStyle? timeTextStyle;
/// `TextStyle` for the colons betwenn the time numbers.
final TextStyle? colonsTextStyle;
/// `TextStyle` for the description
final TextStyle? descriptionTextStyle;
/// Days unit description.
final String daysDescription;
/// Hours unit description.
final String hoursDescription;
/// Minutes unit description.
final String minutesDescription;
/// Seconds unit description.
final String secondsDescription;
/// Defines the width between the colons and the units.
final double spacerWidth;
final Widget? rightWidget;
// 结束的 组件
final Widget? endWidget;
const TimerCountdown({
required this.endTime,
this.format = CountDownTimerFormat.daysHoursMinutesSeconds,
this.enableDescriptions = true,
this.onEnd,
this.timeTextStyle,
this.onTick,
this.colonsTextStyle,
this.descriptionTextStyle,
this.daysDescription = "Days",
this.hoursDescription = "Hours",
this.minutesDescription = "Minutes",
this.secondsDescription = "Seconds",
this.spacerWidth = 10,
this.rightWidget,
this.endWidget,
});
@override
_TimerCountdownState createState() => _TimerCountdownState();
}
class _TimerCountdownState extends State<TimerCountdown> {
bool isEnd = false;
Timer? timer;
late String countd