diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 405e16418..16c08978d 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -13,6 +13,7 @@ import 'package:fluffychat/pangea/choreographer/widgets/it_bar.dart'; import 'package:fluffychat/pangea/choreographer/widgets/start_igc_button.dart'; import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; import 'package:fluffychat/pangea/widgets/chat/chat_floating_action_button.dart'; +import 'package:fluffychat/pangea/widgets/chat/round_timer.dart'; import 'package:fluffychat/utils/account_config.dart'; import 'package:fluffychat/widgets/chat_settings_popup_menu.dart'; import 'package:fluffychat/widgets/connection_status_header.dart'; @@ -119,6 +120,10 @@ class ChatView extends StatelessWidget { // #Pangea } else { return [ + const RoundTimer(), + const SizedBox( + width: 10, + ), ChatSettingsPopupMenu( controller.room, (!controller.room.isDirectChat && !controller.room.isArchived), diff --git a/lib/pangea/widgets/chat/round_timer.dart b/lib/pangea/widgets/chat/round_timer.dart new file mode 100644 index 000000000..15ddf5440 --- /dev/null +++ b/lib/pangea/widgets/chat/round_timer.dart @@ -0,0 +1,88 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; + +/// Create a timer that counts down to the given time +/// Default duration is 180 seconds +class RoundTimer extends StatefulWidget { + final int timerMaxSeconds; + + const RoundTimer({ + super.key, + this.timerMaxSeconds = 180, + }); + + @override + RoundTimerState createState() => RoundTimerState(); +} + +class RoundTimerState extends State { + int currentSeconds = 0; + Timer? _timer; + bool isTiming = false; + + void resetTimer() { + setState(() { + currentSeconds = 0; + }); + } + + String get timerText => + '${((widget.timerMaxSeconds - currentSeconds) ~/ 60).toString().padLeft(2, '0')}: ${((widget.timerMaxSeconds - currentSeconds) % 60).toString().padLeft(2, '0')}'; + + startTimeout([int milliseconds = 1000]) { + _timer = Timer.periodic(const Duration(seconds: 1), (timer) { + setState(() { + currentSeconds++; + if (currentSeconds >= widget.timerMaxSeconds) timer.cancel(); + }); + }); + setState(() { + isTiming = true; + }); + } + + stopTimeout() { + if (_timer != null) { + _timer!.cancel(); + } + setState(() { + isTiming = false; + }); + } + + @override + void initState() { + startTimeout(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Material( + color: const Color.fromARGB(255, 126, 22, 14), + child: Padding( + padding: const EdgeInsets.all( + 5, + ), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(timerText), + // Row( + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // IconButton( + // onPressed: isTiming ? stopTimeout : startTimeout, + // icon: Icon(isTiming ? Icons.pause_circle : Icons.play_circle), + // ), + // ], + // ), + ], + ), + ), + ), + ); + } +}