Bonjour, je souhaite réaliser un Socket IO dans Flutter, pour cela j'utilise l'exemple ci-dessous mais je ne peux pas voir les données que j'émets sur ce canal particulier, j'utilise à la fois l'émulateur et le dispositif physique mais le mot "TEST" que j'émets sur le canal de chat ne s'imprime pas sur la console, merci de m'aider.
Exemple :
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:socket_flutter_plugin/socket_flutter_plugin.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
try {
SocketFlutterPlugin myIO = new SocketFlutterPlugin();
myIO.socket("http://10.2.2.22:9006");
myIO.connect();
String jsonData =
'{"content":"test"}';
myIO.emit("chat",jsonData);
myIO.on("chat",(data){
debugPrint(data.toString());
});
} on PlatformException {
_platformVersion = 'Failed to get platform version.';
}
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Text('Running on: $_platformVersion\n'),
),
),
);
}
}
Sortie : :
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
D/SocketIO (18242): Socket initialised
D/SocketIO (18242): Connected
D/SocketIO (18242): Pushing {"content":"test"} on topic chat
D/SocketIO (18242): registering to chat topic
D/NetworkSecurityConfig(18242): No Network Security Config specified, using platform default
D/ (18242): HostConnection::get() New Host Connection established 0x9fc9d980, tid 18264
D/EGL_emulation(18242): eglMakeCurrent: 0x9c1f32e0: ver 2 0 (tinfo 0x9fc83550)