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

@ -374,6 +374,14 @@ Map<String, TopZaps> topZapReceiver(Iterable<ZapReceipt> zaps) {
);
}
String formatSecondsToHHMMSS(int seconds) {
int hours = seconds ~/ 3600;
int minutes = (seconds % 3600) ~/ 60;
int remainingSeconds = seconds % 60;
return '${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
}
String bech32ToHex(String bech32) {
final decoder = Bech32Decoder();
final data = decoder.convert(bech32, 10_000);

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(),
),
),
);
}
}

View File

@ -5,6 +5,7 @@ import 'package:zap_stream_flutter/theme.dart';
import 'package:zap_stream_flutter/utils.dart';
import 'package:zap_stream_flutter/widgets/button_follow.dart';
import 'package:zap_stream_flutter/widgets/game_info.dart';
import 'package:zap_stream_flutter/widgets/live_timer.dart';
import 'package:zap_stream_flutter/widgets/nostr_text.dart';
import 'package:zap_stream_flutter/widgets/pill.dart';
import 'package:zap_stream_flutter/widgets/profile.dart';
@ -39,14 +40,20 @@ class StreamInfoWidget extends StatelessWidget {
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
if (startedDate != null)
RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5, fontSize: 14),
children: [
TextSpan(text: "Started "),
TextSpan(text: DateFormat().format(startedDate)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
style: TextStyle(color: LAYER_5, fontSize: 14),
children: [
TextSpan(text: "Started "),
TextSpan(text: DateFormat().format(startedDate)),
],
),
),
LiveTimerWidget(started: startedDate),
],
),
if (stream.info.summary?.isNotEmpty ?? false)
Text.rich(