feat: live timer

closes #23
This commit is contained in:
2025-05-16 12:33:34 +01:00
parent dcf42e7a78
commit b5e0822d6c
3 changed files with 72 additions and 8 deletions

View File

@ -0,0 +1,49 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
class LiveTimerWidget extends StatefulWidget {
final DateTime started;
const LiveTimerWidget({super.key, required this.started});
@override
createState() => _LiveTimerWidget();
}
class _LiveTimerWidget extends State<LiveTimerWidget> {
late Timer _timer;
@override
void initState() {
super.initState();
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() {
// tick
});
});
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return PillWidget(
color: LAYER_2,
child: Text(
formatSecondsToHHMMSS(
((DateTime.now().millisecondsSinceEpoch -
widget.started.millisecondsSinceEpoch) /
1000)
.toInt(),
),
),
);
}
}