Adds countdown timer to chat
This commit is contained in:
parent
2b574f42c1
commit
e7f3b9e73a
2 changed files with 93 additions and 0 deletions
|
|
@ -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),
|
||||
|
|
|
|||
88
lib/pangea/widgets/chat/round_timer.dart
Normal file
88
lib/pangea/widgets/chat/round_timer.dart
Normal file
|
|
@ -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<RoundTimer> {
|
||||
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),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue