socket.io for flutter by adhara
supports both Android and iOS
Usage:
See example/lib/main.dart for better example
SocketIOManager manager =SocketIOManager();
SocketIO socket = manager.createInstance('http://192.168.1.2:7000/'); //TODO change the port accordingly
socket.onConnect((data){
print("connected...");
print(data);
socket.emit("message", ["Hello world!"]);
});
socket.on("news", (data){ //sample eventprint("news");
print(data);
});
socket.connect();
///disconnect using ///manager.To request callback on ack:
socket.emitWithAck("message", ["Hello world!"]).then( (data) {
// this callback runs when this specific message is acknowledged by the serverprint(data);
});Open
example/iosin XCode orexample/androidin android studio. Build the code once (cd example&flutter build apk|flutter build ios --no-codesign)cd
example/socket.io.server1 run
npm i2 run
npm startopen
example/lib/main.dartand edit theURIin #7 to point to your hosted/local socket server instances as mentioned step 2For example:
constStringURI="http://192.168.1.2:7000/";
constStringURI="http://mysite.com/";
run Android/iOS app
This project uses Swift for iOS support, please enable Swift support for your project for this plugin to work
Configure android:usesCleartextTraffic="true" as a property of <application ...> tag in android/app/src/main/AndroidManifest.xml
For example:
<applicationandroid:name="io.flutter.app.FlutterApplication"android:label="adhara_socket_io_example"android:usesCleartextTraffic="true"android:icon="@mipmap/ic_launcher">
<activityandroid:name=".MainActivity"...>...</activity>
Feel free to checkout our Adhara package