flutter_socket_io 0.5.1

flutter_socket_io #

Flutter Socket IO Plugin, supported Android + iOS (iOS installation guide is coming soon)

How to install on iOS #

    1. Copy the folder example/ios/Runner/SocketObj to ${PROJECT_ROOT}/ios/Runner/
    1. Replace the example/ios/Runner/AppDelegate.m line with ${PROJECT_ROOT}/ios/Runner/AppDelegate.m. (Notice: You should merge the old one in your project to merge with the new from this plugin if you have some change on that file)
    1. Open ${PROJECT_ROOT}/ios/Podfile, paste this line pod 'Socket.IO-Client-Swift', '~> 13.3.0' before the end of target 'Runner' do block
    1. Run and Enjoy the plugin :)

Use the plugin #

1. Add the following import to your Dart code:

import  'package:flutter_socket_io/flutter_socket_io.dart';

2. SocketIOManager: to manage (create/destroy) list of SocketIO

Create SocketIO with SocketIOManager:

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

Destroy SocketIO with socketIOManager:


3. SocketIO:

Get Id (Url + Namespace) of the socket

String getId();

Create a new socket and connects the client

Future<void> connect();

Init socket before doing anything with socket

Future<void> init();

Subscribe to a channel with a callback

 Future<void> subscribe(String event, Function callback); 

Unsubscribe from a channel. When no callback is provided, unsubscribe all subscribers of the channel. Otherwise, unsubscribe only the callback passed in

Future<void> unSubscribe(String event, [Function callback]); 

Send a message via a channel (i.e. event, the native code will convert string message to JsonObject before sending)

Future<void> sendMessage(String event, dynamic message, [Function callback]);

Disconnect from the socket

Future<void> disconnect(); 

Unsubscribe all subscribers from all channels

Future<void> unSubscribesAll();

4. Example: Link

SocketIO socketIO;
_connectSocket01() { 
	//update your domain before using  
	 socketIO = SocketIOManager().createSocketIO("", "/chat", query: "userId=21031", socketStatusCallback: _socketStatus); 

	//call init socket before doing anything 

	//subscribe event
	socketIO.subscribe("socket_info", _onSocketInfo); 

	//connect socket 

_socketStatus(dynamic data) { 
	print("Socket status: " + data); 

_subscribes() { 
	if (socketIO != null) { 
		socketIO.subscribe("chat_direct", _onReceiveChatMessage); 

void _onReceiveChatMessage(dynamic message) { 
	print("Message from UFO: " + message); 

void _sendChatMessage(String msg) async { 
	if (socketIO != null) { 
		String jsonData = '{"message":{"type":"Text","content": ${(msg != null && msg.isNotEmpty) ? '"${msg}"' : '"Hello SOCKET IO PLUGIN :))"'},"owner":"589f10b9bbcd694aa570988d","avatar":"img/avatar-default.png"},"sender":{"userId":"589f10b9bbcd694aa570988d","first":"Ha","last":"Test 2","location":{"lat":10.792273999999999,"long":106.6430356,"accuracy":38,"regionId":null,"vendor":"gps","verticalAccuracy":null},"name":"Ha Test 2"},"receivers":["587e1147744c6260e2d3a4af"],"conversationId":"589f116612aa254aa4fef79f","name":null,"isAnonymous":null}'; 
		socketIO.sendMessage("chat_direct", jsonData, _onReceiveChatMessage); 

_destroySocket() { 
	if (socketIO != null) { 

0.5.1 #

  • Fixed bug: "@UiThread must be executed on the main thread. Current thread: EventThread" on Flutter version > 1.6.x

0.5.0 #

  • Fixed bug: "@UiThread must be executed on the main thread. Current thread: EventThread" on Flutter version > 1.6.x
  • Upgraded build gradle to 3.4.2.
  • Changed compileSdkVersion to 28

0.4.7 #

  • Upgraded android build configs.

0.4.6 #

  • Fixed bugs: get hashCode function is always equal 1.

0.4.3 #

  • Changed: - init with query option
  • Fixed bug: - added forceNew to create socket instance

0.4.2 #

  • Fixed bug: checked NULL data received before calling back when using sendMessage function* Fixed bug: checked NULL data received from server before calling back when using sendMessage function

0.4.1 #

  • Changed: changed android dependency from "com.github.nkzawa:socket.io-client:0.3.0" to official socket.io "io.socket:socket.io-client:1.0.0"

0.4.0 #

  • Added: The guide for installing this plugin on iOS
  • Added: MIT LICENSE

0.3.8 #

  • Fixed bugs.

0.3.7 #

  • Updated documentation

0.3.3 #

  • Fixed bugs: iOS don't create new SocketManger (with the same domain) if it already existed.

0.3.2 #

  • Fixed bugs.

0.3.0 #

  • Supported iOS (Testing).

0.2.0 #

  • Added function: init() socket (please call this function before doing anything with socket)

0.1.1 #

  • Refactor code.

0.1.0 #

  • Fixed bugs.

0.0.21 #

  • Fixed bugs.

0.0.20 #

  • Fixed bugs.

0.0.19 #

  • Fixed bugs.

0.0.18 #

  • Fixed bugs.

0.0.17 #

  • Set transports = new String[]{WebSocket.NAME};

0.0.16 #

  • Fixed bugs.

0.0.15 #

  • Fixed bugs.
  • Added 'String query' param [optional] when calling connect function

0.0.14 #

  • Fixed bugs.

0.0.12 #

  • Fixed bugs.

0.0.11 #

  • Fixed bugs.
  • Added features: supported calling connect/subscribes/unSubscribes/sendMessage with Flutter's callback Function.
  • Supported OS:
    • Android

0.0.8 #

  • Initial release.
  • Supported:
    • Android
    • iOS: coming soon


flutter_socket_io_example #

Demonstrates how to use the flutter_socket_io plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_socket_io: ^0.5.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_socket_io/flutter_socket_io.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/flutter_socket_io.dart. (-7.71 points)

Analysis of lib/flutter_socket_io.dart reported 16 hints, including:

line 296 col 23: Name non-constant identifiers using lowerCamelCase.

line 297 col 23: Name non-constant identifiers using lowerCamelCase.

line 298 col 23: Name non-constant identifiers using lowerCamelCase.

line 299 col 23: Name non-constant identifiers using lowerCamelCase.

line 300 col 23: Name non-constant identifiers using lowerCamelCase.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/socket_io_manager.dart.

Run flutter format to format lib/socket_io_manager.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8