Open nayanAubie opened 6 months ago
i was facing the same issue no one helped so what i did was i just created listner for every 3 second if my hub is disconnected then do reconnect sample code: import 'dart:async'; import 'package:flutter/material.dart'; import 'package:signalr_core/signalr_core.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('HubConnection Status Checker'), ), body: Center( child: HubConnectionStatusChecker(), ), ), ); } }
class HubConnectionStatusChecker extends StatefulWidget { @override _HubConnectionStatusCheckerState createState() => _HubConnectionStatusCheckerState(); }
class _HubConnectionStatusCheckerState extends State
@override void initState() { super.initState();
// Initialize your HubConnection here
_hubConnection = HubConnectionBuilder()
.withUrl('your_hub_connection_url')
.build();
// Start checking the connection status every second
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
// Check the connection status
if (_hubConnection.state == HubConnectionState.Connected) {
print('HubConnection is connected');
} else {
print('HubConnection is not connected');
// Optionally, try to start the connection again
// _hubConnection.start();
}
});
}
@override void dispose() { // Cancel the timer and dispose the HubConnection _timer.cancel(); _hubConnection.stop(); super.dispose(); }
@override Widget build(BuildContext context) { return Text('Checking HubConnection status...'); } }
and it worked perfectly now i am not facing this issue
facing the same issue in android devices
facing the same issue in android and iOS devices
Reconnecting
andReconnected
.