adhara_socket_io 1.0.0
adhara_socket_io: ^1.0.0 copied to clipboard

Websocket by for flutter by adhara, supports both iOS and Android

adhara_socket_io # for flutter by adhara

supports both Android and iOS


See example/lib/main.dart for more detailed example

	final SOCKET_SERVER = '';	//To be modified accordingly
    SocketIO socket;
	StreamSubscription connectSubscription;
	StreamSubscription echoSubscription;

	Future<void> demonstrateSocket() async {
    	// Create a socket instance
		socket = await SocketIOManager().createInstance(

		// Listen to a socket event
		subscription = socket.onConnect.listen((data){   //listen to socket connect event
		  print('connected: $data');
		  socket.emit('message', ['Hello world!']);

        // Listen to an custom event
		echoSubscription = socket.on('echo', (data){   //listen to 'news' event
		  print("news event recieved with data: $data");

        // connect to socket server - will initialize connection,
        //  but not ensure the connection yet.
        //  If this method used to connect to server, then emit events should be sent
        //  only after ensuring connection to socket server is successful by listening
        //  to onConnect events
		// await socket.connect();

        // This API will ensure connection to server is successful
        //  or will throw error on connect error
        await socket.connectSync();

        // publish data - will publish to server, won't ensure the delivery
		await socket.emit('echo', ['hello']);

        // emit with acknowledgement - will publish to server
        //  and ensure delivery with ack if ack is implemented in server
        dynamic ackData = await socket.emitWithAck('echo', ['hello']);
        print('acknowledgement recieved from server: $ackData');

    Future<void> dispose() async {
    	// cancel echo and onConnect subscriptions
	    await echoSubscription.cancel();
	    await connectSubscription.cancel();

        // clear socket instance from manager
    	await SocketIOManager().clearInstance(socket);

	// register liteners, connect to a socket, and publish data

    // will dispose listeners and socket

Running example: #

  1. clone the project
  2. start socket server in the background
npm i
./node_modules/.bin/pm2/ index.js
cd ../
  1. open example/lib/main.dart and edit the URI in #7 to point to your hosted/local socket server instances as mentioned step 2

    For example:

     const String URI = "";
     const String URI = "";
  2. run example

cd example
flutter run

iOS support 📢📢 #

This project uses Swift for iOS support, please enable Swift support for your project for this plugin to work

Android support for SDK > 27 #

Configure android:usesCleartextTraffic="true" as a property of <application ...> tag in android/app/src/main/AndroidManifest.xml

For example:


Refer to discussion here

Running tests #

This plugin uses flutter driver to run integration tests tests. Use below command to run integration tests on Android/iOS

sh bin/

Sample Video - Running the example #

Running adhara socket io for flutter, example

FAQ's #

AdharaSocketIoPlugin.m:2:9: fatal error: 'adhara_socket_io/adhara_socket_io-Swift.h' file not found

add use_frameworks! to your Podfile as in the example

Read more about this: discussion

Other Packages: #

Feel free to checkout our Adhara package

pub points


Websocket by for flutter by adhara, supports both iOS and Android

Repository (GitHub)
View/report issues


API reference


Apache 2.0 (LICENSE)


flutter, pedantic


Packages that depend on adhara_socket_io