signalr_client
signalr_client copied to clipboard
Getting connection message as Disconnected and while trying to send message getting exception.
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:
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(); }