GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
930 stars 342 forks source link

livestream use case, no members when sending message #590

Closed Abacaxi-Nelson closed 3 years ago

Abacaxi-Nelson commented 3 years ago

Describe the bug Trying to add chat like YouTube. Using some of your example package. Error cause members is null when sending message.

What package are you using? What version? Last

What platform is it about? iOS

Code

final client = StreamChat.of(context).client;
final channel = client.channel(
      'livestream',
      id: postId,
    );

if (channel.state == null) {
      await channel.watch();
}

await Navigator.of(
      context,
      rootNavigator: true,
    ).push(
      MaterialPageRoute(
          builder: (context) => StreamChannel(
                channel: channel,
                child: const ChannelPage(), // From your example package
              ),
          fullscreenDialog: true),
    );

Error

final currentUserMember =
        members.firstWhere((e) => e.user!.id == currentUser!.id);

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following StateError was thrown building:
flutter: Bad state: No element
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      ListMixin.firstWhere (dart:collection/list.dart:167:5)
flutter: #1      _MessageListViewState.buildMessage
package:stream_chat_flutter/src/message_list_view.dart:930
flutter: #2      _MessageListViewState._buildBottomMessage
package:stream_chat_flutter/src/message_list_view.dart:750
flutter: #3      _MessageListViewState._buildListView.<anonymous closure>.<anonymous closure>
package:stream_chat_flutter/src/message_list_view.dart:56

Maybe im not using 'livestream' channels correctly; but isn't It suppose to allow everyone to post a message without being a member ? or member is added dynamically ?

Thank you, Nelson

Abacaxi-Nelson commented 3 years ago

Ooo i may not be up to date

Abacaxi-Nelson commented 3 years ago

Okay I get it. Here its fix

https://github.com/GetStream/stream-chat-flutter/blob/7f589edeb122818afac015a4189f903ab085864b/packages/stream_chat_flutter/lib/src/message_list_view.dart#L819

But same code here is not

https://github.com/GetStream/stream-chat-flutter/blob/7f589edeb122818afac015a4189f903ab085864b/packages/stream_chat_flutter/lib/src/message_list_view.dart#L967

I think that's the problem :)