add channel, user and messages db
This commit is contained in:
@@ -215,7 +215,10 @@ class _ChannelListViewState extends State<ChannelListView> {
|
||||
if (i < channels.length) {
|
||||
final channel = channels[i];
|
||||
|
||||
final channelClient = streamChat.client.channels[channel.cid];
|
||||
final channelClient = streamChat.channels.firstWhere(
|
||||
(c) => c.cid == channel.cid,
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
ChannelTapCallback onTap;
|
||||
if (widget.onChannelTap != null) {
|
||||
|
||||
@@ -110,15 +110,15 @@ class ChannelPreview extends StatelessWidget {
|
||||
initialData: channel.state.messages,
|
||||
builder: (context, snapshot) {
|
||||
final messages = snapshot.data;
|
||||
final lastMessage = messages.isNotEmpty ? messages.last : null;
|
||||
final lastMessage = messages?.isNotEmpty == true ? messages.last : null;
|
||||
if (lastMessage == null) {
|
||||
return SizedBox();
|
||||
}
|
||||
|
||||
String text;
|
||||
String text = lastMessage.text;
|
||||
if (lastMessage.isDeleted) {
|
||||
text = 'This message was deleted.';
|
||||
} else {
|
||||
} else if (lastMessage.attachments != null) {
|
||||
final prefix = lastMessage.attachments
|
||||
.map((e) {
|
||||
if (e.type == 'image') {
|
||||
|
||||
+31
-25
@@ -101,7 +101,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
widget.message.isDeleted
|
||||
? _buildDeletedMessage(alignment)
|
||||
: _buildBubble(context),
|
||||
if (_streamChannel.channel.config.replies)
|
||||
if (_streamChannel.channel.config?.replies == true)
|
||||
_buildThreadIndicator(context),
|
||||
if (!_isNextUser) _buildTimestamp(alignment),
|
||||
],
|
||||
@@ -146,7 +146,8 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
UserAvatar(user: widget.message.user),
|
||||
if (_isMyMessage &&
|
||||
widget.nextMessage == null &&
|
||||
widget.message.status == MessageSendingStatus.SENT)
|
||||
(widget.message.status == MessageSendingStatus.SENT ||
|
||||
widget.message.status == null))
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 1.0,
|
||||
@@ -278,28 +279,30 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
var nOfAttachmentWidgets = 0;
|
||||
|
||||
final column =
|
||||
List<Widget>.from(widget.message.attachments.map((attachment) {
|
||||
nOfAttachmentWidgets++;
|
||||
List<Widget>.from(widget.message.attachments?.map((attachment) {
|
||||
nOfAttachmentWidgets++;
|
||||
|
||||
Widget attachmentWidget;
|
||||
if (attachment.type == 'video') {
|
||||
attachmentWidget = _buildVideo(attachment);
|
||||
} else if (attachment.type == 'image' || attachment.type == 'giphy') {
|
||||
attachmentWidget = _buildImage(attachment);
|
||||
}
|
||||
Widget attachmentWidget;
|
||||
if (attachment.type == 'video') {
|
||||
attachmentWidget = _buildVideo(attachment);
|
||||
} else if (attachment.type == 'image' ||
|
||||
attachment.type == 'giphy') {
|
||||
attachmentWidget = _buildImage(attachment);
|
||||
}
|
||||
|
||||
if (attachmentWidget != null) {
|
||||
return _buildAttachment(
|
||||
attachmentWidget,
|
||||
attachment,
|
||||
nOfAttachmentWidgets,
|
||||
context,
|
||||
);
|
||||
}
|
||||
if (attachmentWidget != null) {
|
||||
return _buildAttachment(
|
||||
attachmentWidget,
|
||||
attachment,
|
||||
nOfAttachmentWidgets,
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
nOfAttachmentWidgets--;
|
||||
return SizedBox();
|
||||
}));
|
||||
nOfAttachmentWidgets--;
|
||||
return SizedBox();
|
||||
}) ??
|
||||
[]);
|
||||
|
||||
if (widget.message.text.trim().isNotEmpty) {
|
||||
String text = widget.message.text;
|
||||
@@ -312,7 +315,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
? CrossAxisAlignment.end
|
||||
: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
if (_streamChannel.channel.config.reactions &&
|
||||
if (_streamChannel.channel.config?.reactions == true &&
|
||||
nOfAttachmentWidgets == 0)
|
||||
Align(
|
||||
child: _buildReactions(),
|
||||
@@ -323,7 +326,9 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
Stack(
|
||||
overflow: Overflow.visible,
|
||||
children: <Widget>[
|
||||
if (nOfAttachmentWidgets == 0) _buildReactionPaint(),
|
||||
if (nOfAttachmentWidgets == 0 &&
|
||||
_streamChannel.channel.config?.reactions == true)
|
||||
_buildReactionPaint(),
|
||||
_buildMessageText(nOfAttachmentWidgets, text, context),
|
||||
],
|
||||
),
|
||||
@@ -333,7 +338,8 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
);
|
||||
}
|
||||
|
||||
if (_streamChannel.channel.config.reactions && nOfAttachmentWidgets > 0) {
|
||||
if (_streamChannel.channel.config?.reactions == true &&
|
||||
nOfAttachmentWidgets > 0) {
|
||||
column.insert(
|
||||
0,
|
||||
Align(
|
||||
@@ -991,7 +997,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive {
|
||||
return widget.message.attachments.isNotEmpty;
|
||||
return widget.message.attachments?.isNotEmpty == true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,19 +171,6 @@ class StreamChatState extends State<StreamChat> {
|
||||
return theme;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_subscriptions.add(widget.client.on('message.new').listen((Event e) {
|
||||
final index = channels.indexWhere((c) => c.cid == e.cid);
|
||||
if (index > 0) {
|
||||
final channel = channels.removeAt(index);
|
||||
channels.insert(0, channel);
|
||||
_channelsController.add(channels);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// The current user
|
||||
User get user => widget.client.state.user;
|
||||
|
||||
@@ -191,12 +178,10 @@ class StreamChatState extends State<StreamChat> {
|
||||
Stream<User> get userStream => widget.client.state.userStream;
|
||||
|
||||
/// The current channel list
|
||||
final List<Channel> channels = [];
|
||||
List<Channel> get channels => client.state.channels;
|
||||
|
||||
/// The current channel list as a stream
|
||||
Stream<List<Channel>> get channelsStream => _channelsController.stream;
|
||||
|
||||
final BehaviorSubject<List<Channel>> _channelsController = BehaviorSubject();
|
||||
Stream<List<Channel>> get channelsStream => client.state.channelsStream;
|
||||
|
||||
final BehaviorSubject<bool> _queryChannelsLoadingController =
|
||||
BehaviorSubject.seeded(false);
|
||||
@@ -218,16 +203,12 @@ class StreamChatState extends State<StreamChat> {
|
||||
_queryChannelsLoadingController.sink.add(true);
|
||||
|
||||
try {
|
||||
final res = await widget.client.queryChannels(
|
||||
await widget.client.queryChannels(
|
||||
filter: filter,
|
||||
sort: sortOptions,
|
||||
options: options,
|
||||
paginationParams: paginationParams,
|
||||
);
|
||||
channels.addAll(res);
|
||||
_channelsController.sink.add(channels);
|
||||
} catch (e) {
|
||||
_channelsController.sink.addError(e);
|
||||
} finally {
|
||||
_queryChannelsLoadingController.sink.add(false);
|
||||
}
|
||||
@@ -243,7 +224,6 @@ class StreamChatState extends State<StreamChat> {
|
||||
widget.client.dispose();
|
||||
_subscriptions.forEach((s) => s.cancel());
|
||||
_queryChannelsLoadingController.close();
|
||||
_channelsController.close();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -20,7 +20,8 @@ dependencies:
|
||||
file_picker: ^1.4.3+2
|
||||
image_picker: ^0.6.3+4
|
||||
keyboard_visibility: ^0.5.6
|
||||
stream_chat: ^0.1.18
|
||||
stream_chat:
|
||||
path: ../stream_chat_dart
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.9.0
|
||||
|
||||
Reference in New Issue
Block a user