Skip to content
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 support #11

Closed
mrleesin opened this issue Jan 23, 2019 · 6 comments
Closed

Flutter support #11

mrleesin opened this issue Jan 23, 2019 · 6 comments
Labels

Comments

@mrleesin
Copy link

still not working?

@jumperchen
Copy link
Member

Have you tried with the latest version?

@mrleesin
Copy link
Author

screenshot 2019-01-24 at 11 24 18

And nothing happened at all (

@jumperchen
Copy link
Member

We tested on Flutter 1.1.4 with this example, and it works on both Android and iOS.

@mrleesin
Copy link
Author

Still no connection

@jumperchen
Copy link
Member

I created a new app to test, and it works as well.

main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:socket_io_client/socket_io_client.dart' as IO;

void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    IO.Socket socket = IO.io('http://YourIPAddress:3000', <String, dynamic>{'transports': ['websocket']});
  socket.on('connect', (_) {
    print('connect');
    socket.emit('msg', 'init');
    int count = 0;
    new Timer.periodic(const Duration(seconds: 1), (Timer countDownTimer) {
      socket.emit('msg', count++);
    });
  });
  socket.on('event', (data) => print(data));
  socket.on('disconnect', (_) => print('disconnect'));
  socket.on('fromServer', (_) => print(_));
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }

}

Note: You should use IP address rather than localhost:3000 here. (it's running on android vm)

The result in console:

screen shot 2019-01-25 at 12 12 03 pm

@mrleesin
Copy link
Author

Awesome! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants