Minor refactoring

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2020-12-28 23:32:57 +05:30
parent 38e3d541bb
commit 27a83e7791
+8 -14
View File
@@ -16,8 +16,6 @@ import 'package:stream_chat_flutter/src/stream_chat.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'stream_channel.dart';
class ImageFooter extends StatefulWidget { class ImageFooter extends StatefulWidget {
/// Callback to call when pressing the back button. /// Callback to call when pressing the back button.
/// By default it calls [Navigator.pop] /// By default it calls [Navigator.pop]
@@ -66,8 +64,7 @@ class _ImageFooterState extends State<ImageFooter> {
TextEditingController _messageController = TextEditingController(); TextEditingController _messageController = TextEditingController();
FocusNode _messageFocusNode = FocusNode(); FocusNode _messageFocusNode = FocusNode();
String _userNameQuery; String _channelNameQuery;
bool _isSearchActive = false;
List<Channel> _selectedChannels = []; List<Channel> _selectedChannels = [];
bool _loading = false; bool _loading = false;
@@ -81,8 +78,7 @@ class _ImageFooterState extends State<ImageFooter> {
_debounce = Timer(const Duration(milliseconds: 350), () { _debounce = Timer(const Duration(milliseconds: 350), () {
if (mounted && modalSetStateCallback != null) { if (mounted && modalSetStateCallback != null) {
modalSetStateCallback(() { modalSetStateCallback(() {
_userNameQuery = _searchController.text; _channelNameQuery = _searchController.text;
_isSearchActive = _userNameQuery.isNotEmpty;
}); });
} }
}); });
@@ -294,15 +290,15 @@ class _ImageFooterState extends State<ImageFooter> {
child: ChannelsBloc( child: ChannelsBloc(
child: ChannelListView( child: ChannelListView(
selectedChannels: _selectedChannels, selectedChannels: _selectedChannels,
onChannelTap: (user, _) { onChannelTap: (channel, _) {
_searchController.clear(); _searchController.clear();
if (!_selectedChannels.contains(user)) { if (!_selectedChannels.contains(channel)) {
modalSetState(() { modalSetState(() {
_selectedChannels.add(user); _selectedChannels.add(channel);
}); });
} else { } else {
modalSetState(() { modalSetState(() {
_selectedChannels.remove(user); _selectedChannels.remove(channel);
}); });
} }
}, },
@@ -313,7 +309,7 @@ class _ImageFooterState extends State<ImageFooter> {
filter: { filter: {
if (_searchController.text.isNotEmpty) if (_searchController.text.isNotEmpty)
'name': { 'name': {
r'$autocomplete': _userNameQuery, r'$autocomplete': _channelNameQuery,
}, },
'id': { 'id': {
r'$ne': StreamChat.of(context).user.id, r'$ne': StreamChat.of(context).user.id,
@@ -346,7 +342,7 @@ class _ImageFooterState extends State<ImageFooter> {
), ),
), ),
Text( Text(
'No user matches these keywords...'), 'No chat matches these keywords...'),
], ],
), ),
), ),
@@ -624,8 +620,6 @@ class _ImageFooterState extends State<ImageFooter> {
_messageController.clear(); _messageController.clear();
final client = StreamChat.of(context).client;
for (var channel in _selectedChannels) { for (var channel in _selectedChannels) {
final message = Message( final message = Message(
text: text, text: text,