Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting connection message as Disconnected and while trying to send message getting exception. #18

Open
DhavalRKansara opened this issue Sep 12, 2019 · 1 comment

Comments

@DhavalRKansara
Copy link

I run your Chat client/server example but at home screen, I am getting the message as disconnected and while I try to send message getting below exceptions.

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Cannot start a connection that is not in the 'Disconnected' state.
#0      HubConnection.start (package:signalr_client/hub_connection.dart:103:5)
<asynchronous suspension>
#1      ChatPageViewModel.openChatConnection (package:chatclient/views/pages/chatPageViewModel.dart:63:28)
<asynchronous suspension>
#2      ChatPageViewModel.sendChatMessage (package:chatclient/views/pages/chatPageViewModel.dart:72:11)
<asynchronous suspension>
#3      _MessageComposeViewState.build.<anonymous closure> (package:chatclient/views/pages/chatPage.dart:136:35)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
#5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:729:32)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
#8      TapGestureRecognizer.handlePrim<…>

My Home screen:

Simulator Screen Shot - iPhone Xʀ - 2019-09-12 at 14 18 19

@edihasaj
Copy link

The problem is in this part of the code, when the hub connection is starting is not setting _connectionsIsOpen to true, then the state is connected but _connectionIsOpen is not.

if (_hubConnection.state != HubConnectionState.Connected) {
await _hubConnection.start();
_connectionIsOpen = true;
}

I set the _conncetionIsOpen = true above the hub connection start and it works but this is not a good solution, because the connection cannot start for whatever reason, you should validate it first

if (_hubConnection.state != HubConnectionState.Connected) {
_connectionIsOpen = true;
await _hubConnection.start();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants