-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter Port #4
Comments
Yes, porting to Flutter version is in our roadmap. |
Awesome! Glad to hear it :) Do you guys have a roadmap posted anywhere? (Curious about timeline as I'm tempted on using Flutter for a personal project) |
No, we don't have a specific schedule yet at the moment. |
I would love a pure flutter port. Or even just pointing me in the right direction to being able to be used in flutter. |
Looking forward to this |
Can't wait for this as well |
Still waiting for it... |
Please add support with flutter !! It must be really helpful of developing apps ! |
This would be super helpful for all of us. Definitely looking forward to the flutter port! |
Me too! I'm a highschool student, but I'm willing to learn and maybe help if there's something for me to do! |
and finally i have finished by using plugin.! Export both android and ios socket.io libs to flutter and then call it from dart side ! |
@CircleCurve Can you explain or post your solution to this? |
@QoLTech First i need to say it does not a pure flutter port. I use native plugin and communicate with dart
Let's say your package name is com.example.testplugin public class MainActivity extends FlutterActivity {
private static final String CALLBACK_CHANNEL = "com.example.testplugin/callback" ;
private Socket mSocket ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
final MethodChannel channel = new MethodChannel(getFlutterView(), CALLBACK_CHANNEL) ;
channel.setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("addCallBack")) {
Log.d("DEBUG_MSG" , "go init socket") ;
connectSocket(channel);
/*
Map<String, String> params = new HashMap<String, String>() ;
params.put("success" , "wow") ;
channel.invokeMethod("onSuccess" , params);*/
}else{
result.notImplemented();
}
}
}
);
//=========Socket=============
private void connectSocket(final MethodChannel channel) {
try {
mSocket = IO.socket("http://your_socket_io:8000") ; //in nodejs you may say that is localhost:3000, 127.0.0.1:3000...etc
mSocket.on("time_counter", new Emitter.Listener() {
@Override
public void call(Object... args) {
channel.invokeMethod("onSuccess", args[0].toString());
}
}) ;
mSocket.connect() ;
Log.d("DEBUG_MSG" , "connect success") ;
}catch (URISyntaxException e) {
Log.d("DEBUG_MSG" , "connect fail : " + e.toString()) ;
}
}
} Now, you have created a plugin of socket.io in android-side and listen on time counter event (you can write it your own event) In dart-side, you need to make a listener to listen a call from java!
import 'dart:async' ;
import 'dart:convert' ;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text("Test plugin"),
),
body: MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const platformCallback = const MethodChannel("com.example.testplugin/callback") ;
Future<Null> _callBack() async {
platformCallback.setMethodCallHandler((MethodCall call) {
switch(call.method){
case "onSuccess" :
print("onSuccess") ;
Map<String, dynamic> rtn = JSON.decode(call.arguments);
String title = rtn["message"][0]["title"].toString() ;
String basePrice = rtn["message"][0]["basePrice"].toString() ;
String currentPrice = rtn["message"][0]["currentPrice"].toString() ;
String perBid = rtn["message"][0]["perBid"].toString() ;
String bidder = rtn["message"][0]["bidder"].toString() ;
String expireTime = rtn["message"][0]["expireTime"].toString() ;
String deal = rtn["message"][0]["deal"].toString() ;
print(expireTime) ;
//print(call.arguments["message"]) ;
break ;
case "onFail" :
print("onFail") ;
break ;
case "onCancel" :
print("onCancel") ;
break ;
}
});
await platformCallback.invokeMethod('addCallBack', {"tag" : "tags"});
} Finally, i hope that can help someone!! haha Reference |
I would definitely prefer a "normal" flutter package. Therefore I am also waiting for the Flutter version |
+1 |
Can't wait to try this features!!! |
Any updates? |
I'm still waiting for this as well :D |
+1 |
Flutter Socket.io |
@aravind-ig does the package really works? i got infinity |
@ahmadudin yes, I'm currently using it in not production apps |
@marianoarga i don't know why, but everytime i'm using it, my build would always stuck at |
Or did i do it wrong? |
It's hard to know, try in another location, maybe you are behind a proxy, try "flutter packages get -v" and take a look at the output |
@marianoarga I just try to use it again and now somehow it can compile just right. But still, i can't figure how to use it yet. Do yo have any example on how to use it? |
@marianoarga for example, how can i do this in flutter? socket.emit('find', 'messages', { status: 'read', user: 10 }, (error, data) => {
console.log('Found all messages', data);
}); i've tried like socketIO.sendMessage("find", "messages", (dynamic data) {print(data);}); but the second argument( |
@ahmadudin
Note: I would use just method (find), and move the entity type (messages) to the Json request. |
@marianoarga does it means that i have to change socket.io configuration in my server? my node server is throwing error because the second arguments should be string, not json. |
@ahmadudin For sure, that will be simpler than modify flutter_socket_io plugin I think... |
@marianoarga i don't think so, the socket.io configuration on my server is handled by feathersjs |
For anyone who have the same problem as me, try this pugin |
Hi, does anyone know how to set the path parameter on creating socket io connection, like here: |
I has searched a bit, but i doesn't find the repository of creator :( i want improve the library him... |
I cloned the code in my repo and left the code open to improvements and I hope someone contributed improvements to motivate put it in DartPackages again. I updated adding the namespace optional parameter. https://github.com/vinicioslc/socket_io_flutter |
@vinicioslc please contact the author at the plugin contact email: He is very active and you can have a nice talk. |
How to use custom path? socketIO = SocketIOManager().createSocketIO("http://10.0.2.2:3000/test", "", socketStatusCallback: _socketStatus);` |
@kazrulit @marianoarga @ahmadudin did you find the way to set path parameter? |
Any updates on this? @jumperchen @felangel |
…ibrary.html and dart.library.io on #4 Flutter Port
closed by this commit - 88a2a09 |
I am trying to implement this socket io package in IOS platform, but its throwing error, I have followed the suggestions and implementation part like in the document ( Instructions they gave ), still not working. Error msg:
|
For all having issues with custom path parameter, I got around this by using adhara_socket_io package. Implementation is similar to this one. |
Is there any plan for a Flutter version of this?
The text was updated successfully, but these errors were encountered: