How to connect flask scoketIO to my flutter chat APP

526 Views Asked by At

How to connect my flutter app to flask_socketIO python ? In flutter i am making a chat APP whose backend to fetch the users is in flask bakcend. So how should i connect both of them ?

1

There are 1 best solutions below

2
Yue Hern On

you can use this package flutter_socket_io

Initialize your socket io server

SocketIO socketIO = SocketIOManager()
                      .createSocketIO("http://127.0.0.1:3000", 
                      "/chat", 
                      query: "userId=21031", 
                      socketStatusCallback: _socketStatus);  

Initialization and subscription to your socket backend

socketIO.init(); 
socketIO.subscribe("socket_info", _onSocketInfo); 
socketIO.connect(); 

Add a callback function to listen for any new information coming in and do whatever u want with the data

_socketStatus(dynamic data) { 
    //do whatever
    print("Socket status: " + data); 
}