call streamchannel.of just once

This commit is contained in:
Salvatore Giordano
2021-08-20 14:41:35 +02:00
parent fea90d4afd
commit 071b337194
@@ -355,11 +355,12 @@ class MessageInputState extends State<MessageInput> {
} }
void _startSlowMode() { void _startSlowMode() {
if (StreamChannel.of(context).channel.cooldownStartedAt != null) { final channel = StreamChannel.of(context).channel;
_cooldownStartedAt = StreamChannel.of(context).channel.cooldownStartedAt; if (channel.cooldownStartedAt != null) {
_cooldownStartedAt = channel.cooldownStartedAt;
if (DateTime.now().difference(_cooldownStartedAt!).inSeconds < if (DateTime.now().difference(_cooldownStartedAt!).inSeconds <
StreamChannel.of(context).channel.cooldown!) { channel.cooldown!) {
_timeOut = StreamChannel.of(context).channel.cooldown! - _timeOut = channel.cooldown! -
DateTime.now().difference(_cooldownStartedAt!).inSeconds; DateTime.now().difference(_cooldownStartedAt!).inSeconds;
_slowModeTimer = Timer.periodic(const Duration(seconds: 1), (timer) { _slowModeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (_timeOut == 0) { if (_timeOut == 0) {