1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] I have issue in flutter with error RealtimeSubscribeException

Discussão em 'Mobile' iniciado por Stack, Outubro 14, 2024 às 05:22.

  1. Stack

    Stack Membro Participativo

    I always receive an error


    RethrownDartError: RealtimeSubscribeException(status: RealtimeSubscribeStatus.channelError, details: RealtimeCloseEvent(code: 1000, reason: ))

    here is my code so far what I did.

    I can not find solution. I think the issue in stream

    class ScheduleApi {
    final SupabaseClient _supabaseClient;

    ScheduleApi(this._supabaseClient);

    Stream<List<BranchesModel>> fetchBranches() {
    try {
    return _supabaseClient
    .from('branches')
    .stream(primaryKey: ['id'])
    .order('name', ascending: true)
    .map((event) {
    final branchesList = event
    .map(
    (e) => BranchesModel.fromJson(e),
    )
    .toList();
    if (branchesList.isEmpty) {
    throw 'No Branches Found';
    }
    return branchesList;
    });
    } catch (e) {
    rethrow;
    }
    }



    class BranchesBloc extends Bloc<BranchesEvent, BranchesState> {
    final FetchBranchesUsecase _fetchBranchesUsecase;
    StreamSubscription<List<BranchesEntity>>? _streamSubscription;
    BranchesBloc(
    this._fetchBranchesUsecase,
    ) : super(const _Loading()) {
    on<BranchesEvent>((event, emit) async {
    await event.when(
    stream: () async {
    try {
    if (_streamSubscription != null) {
    await _streamSubscription!.cancel();
    }
    _streamSubscription = _fetchBranchesUsecase().listen(
    (branchesList) => add(
    BranchesEvent.update(branchesList),
    ),
    onError: (error) =>
    add(BranchesEvent.failed(error.toString())));
    } catch (e) {
    emit(BranchesState.failed(e.toString()));
    }
    },
    update: (branchesList) async {
    emit(BranchesState.loaded(branchesList));
    },
    failed: (error) async {
    emit(BranchesState.failed(error.toString()));
    },
    );
    });
    }
    @override
    Future<void> close() {
    _streamSubscription!.cancel();
    return super.close();
    }
    }


    I think the error in bloc in supabase

    Continue reading...

Compartilhe esta Página