From 9082e50532a92c2dac327998a68b9810c17d7e84 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 1 Mar 2021 17:58:47 +0530 Subject: [PATCH] feat: Removed mute delay (#11) Co-authored-by: Salvatore Giordano --- stream_chat_v1/lib/chat_info_screen.dart | 36 ++++++++++++++++------- stream_chat_v1/lib/group_info_screen.dart | 31 ++++++++++++------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/stream_chat_v1/lib/chat_info_screen.dart b/stream_chat_v1/lib/chat_info_screen.dart index db2999f..4904889 100644 --- a/stream_chat_v1/lib/chat_info_screen.dart +++ b/stream_chat_v1/lib/chat_info_screen.dart @@ -18,6 +18,14 @@ class ChatInfoScreen extends StatefulWidget { } class _ChatInfoScreenState extends State { + ValueNotifier mutedBool = ValueNotifier(false); + + @override + void initState() { + super.initState(); + mutedBool = ValueNotifier(StreamChannel.of(context).channel.isMuted); + } + @override Widget build(BuildContext context) { final channel = StreamChannel.of(context).channel; @@ -134,6 +142,8 @@ class _ChatInfoScreenState extends State { StreamBuilder( stream: StreamChannel.of(context).channel.isMutedStream, builder: (context, snapshot) { + mutedBool.value = snapshot.data; + return OptionListTile( tileColor: StreamChatTheme.of(context).colorTheme.whiteSnow, title: 'Mute user', @@ -150,16 +160,22 @@ class _ChatInfoScreenState extends State { ), trailing: snapshot.data == null ? CircularProgressIndicator() - : CupertinoSwitch( - value: snapshot.data, - onChanged: (val) { - if (snapshot.data) { - channel.channel.unmute(); - } else { - channel.channel.mute(); - } - }, - ), + : ValueListenableBuilder( + valueListenable: mutedBool, + builder: (context, value, _) { + return CupertinoSwitch( + value: value, + onChanged: (val) { + mutedBool.value = val; + + if (snapshot.data) { + channel.channel.unmute(); + } else { + channel.channel.mute(); + } + }, + ); + }), onTap: () {}, ); }), diff --git a/stream_chat_v1/lib/group_info_screen.dart b/stream_chat_v1/lib/group_info_screen.dart index 9327891..ed72afa 100644 --- a/stream_chat_v1/lib/group_info_screen.dart +++ b/stream_chat_v1/lib/group_info_screen.dart @@ -29,6 +29,8 @@ class _GroupInfoScreenState extends State { bool listExpanded = false; + ValueNotifier mutedBool = ValueNotifier(false); + void _userNameListener() { if (_searchController.text == _userNameQuery) { return; @@ -54,6 +56,7 @@ class _GroupInfoScreenState extends State { _nameController.addListener(() { setState(() {}); }); + mutedBool = ValueNotifier(StreamChannel.of(context).channel.isMuted); } @override @@ -434,6 +437,8 @@ class _GroupInfoScreenState extends State { StreamBuilder( stream: StreamChannel.of(context).channel.isMutedStream, builder: (context, snapshot) { + mutedBool.value = snapshot.data; + return OptionListTile( tileColor: StreamChatTheme.of(context).colorTheme.whiteSnow, separatorColor: @@ -452,16 +457,22 @@ class _GroupInfoScreenState extends State { ), trailing: snapshot.data == null ? CircularProgressIndicator() - : CupertinoSwitch( - value: snapshot.data, - onChanged: (val) { - if (snapshot.data) { - channel.channel.unmute(); - } else { - channel.channel.mute(); - } - }, - ), + : ValueListenableBuilder( + valueListenable: mutedBool, + builder: (context, value, _) { + return CupertinoSwitch( + value: value, + onChanged: (val) { + mutedBool.value = val; + + if (snapshot.data) { + channel.channel.unmute(); + } else { + channel.channel.mute(); + } + }, + ); + }), onTap: () {}, ); }),