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
918 stars 337 forks source link

type '_$Loading<int, Channel>' is not a subtype of type 'Success<int, Channel>' in type cast #1894

Open flodaniel opened 5 months ago

flodaniel commented 5 months ago

Which packages are you using?

stream_chat, stream_chat_flutter, stream_chat_flutter_core, stream_chat_persistance, stream_chat_localizations

On what platforms did you experience the issue?

iOS, Android

What version are you using?

stream_chat_flutter: 8.0.0-beta.2 stream_chat_localizations: 8.0.0-beta.2 stream_chat_persistence: 8.0.0-beta.2

What happened?

We see this crash in our production apps, but don't know when and why it is occurring:

_TypeError: type '_$Loading<int, Channel>' is not a subtype of type 'Success<int, Channel>' in type cast
  File "paged_value_notifier.dart", line 123, in PagedValue.asSuccess
  File "paged_value_notifier.dart", line 32, in PagedValueNotifier.currentItems
  File "stream_channel_list_event_handler.dart", line 75, in StreamChannelListEventHandler.onChannelVisible

We use a StreamChannelListController to display a list of channels in our app.

Steps to reproduce

I can't reproduce this locally at the moment, but in all crashes we see we record a "foreground" or a "DEVICE_IDLE_MODE_CHANGED" (on android) event always right before this crash occurs.

Supporting info to reproduce

This is our my_channels_bloc, which us responsible for getting the list of channels to show

MyChannelsBloc Code ```dart class MyChannelsBloc extends Bloc { MyChannelsBloc( this._userRepository, ) : super(const MyChannelsInitial()) { _initController(); on(_onMyChannelsLoaded); on(_onMyChannelsRefreshed); on(_onMyChannelsListenerLoadSucceeded); on(_onMyChannelsListenerLoadFailed); on(_onMyChannelsListenerLoadStarted); } final UserRepository _userRepository; late final StreamChannelListController _channelListController; late final void Function() _channelListener; @override Future close() { _channelListController ..removeListener(_channelListener) ..dispose(); return super.close(); } void _onMyChannelsLoaded( MyChannelsLoaded event, Emitter emit, ) async { await StreamChatService.existing().initialized; await _channelListController.loadMore(event.nextPageKey); } void _onMyChannelsRefreshed( MyChannelsRefreshed event, Emitter emit, ) async { final user = await StreamChatService.existing().initialized; if (!user.online) { unawaited(_waitForReconnect()); return; } await _channelListController.refresh(resetValue: true); } void _onMyChannelsListenerLoadSucceeded( MyChannelsListenerLoadSucceeded event, Emitter emit, ) { emit(MyChannelsLoadSuccess( event.value.items, event.value.nextPageKey, )); } void _onMyChannelsListenerLoadFailed( MyChannelsListenerLoadFailed event, Emitter emit, ) { emit(const MyChannelsLoadError()); } void _onMyChannelsListenerLoadStarted( MyChannelsListenerLoadStarted event, Emitter emit, ) { emit(const MyChannelsLoading()); } Future _initController() async { final user = await StreamChatService.existing().initialized; _channelListController = StreamChannelListController( client: StreamChatService.client, filter: Filter.and( [ Filter.equal('type', 'messaging'), Filter.equal( 'recommendationMode', RecommendationMode.groupsV2Recommendation .toSnakeCase() .toUpperCase(), ), Filter.in_( 'members', [ StreamChatHelper.convertUsernameToStreamUsername( _userRepository.user.username) ], ), ], ), ); _initChannelListener(); if (!user.online) { add(const MyChannelsListenerLoadFailed()); unawaited(_waitForReconnect()); return; } await _channelListController.doInitialLoad(); } Future _waitForReconnect() async { await _channelListController.client.wsConnectionStatusStream .firstWhere((event) => event == ConnectionStatus.connected) .then((event) async { await _channelListController.doInitialLoad(); }); } void _initChannelListener() { _createChannelListener(); _channelListController.addListener(_channelListener); } void _createChannelListener() { _channelListener = () { _channelListController.value.map( (paged_value_notifier.Success value) { add(MyChannelsListenerLoadSucceeded(value)); }, loading: (_) { add(const MyChannelsListenerLoadStarted()); }, error: (e) { add(const MyChannelsListenerLoadFailed()); unawaited(SentryService().recordError( e, stackTrace: StackTrace.current, )); }, ); }; } } ```

Relevant log output

No response

Flutter analyze output

No response

Flutter doctor output

No response

Code of Conduct

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 20 days with no activity.

flodaniel commented 5 months ago

bump

KestasVenslauskas commented 2 months ago

Having the same issue here

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 20 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 7 days since being marked as stale.