我是扑扑发展的新手。当来自包import 'package:socket_io/socket_io.dart';
的{{1}}时出现上述错误
我正在尝试将Node js后端套接字连接到Flutter应用。我不使用模拟器,而是使用Samsung Tab作为外部设备。
这是我的客户程序
socket_io: ^0.9.0+1
这是pubspec.ymal
void main() {
var io = new Server();
var nsp = io.of('/some');
nsp.on('connection', (Socket client) {
print('connection /some');
client.on('msg', (data) {
print('data from /some => $data');
client.emit('fromServer', "ok 2");
});
});
io.on('connection', (Socket client) {
print('connection default namespace');
client.on('msg', (data) {
print('data from default => $data');
client.emit('fromServer', "ok");
});
});
io.listen(3000);
// Dart client
IO.Socket socket = IO.io('http://localhost:3000');
socket.on('connect', (_) {
print('connect');
socket.emit('msg', 'test');
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
socket.on('fromServer', (_) => print(_));
runApp(new MyApp());
}
这是我的后端服务,可以很好地写在节点上
: chat_app
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
socket_io: ^0.9.0+1
socket_io_client: ^0.9.1
http: ^0.12.0
reflectable: ^2.0.9
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
我希望我找不到答案,为什么会发生这种情况以及如何解决。 请帮助
答案 0 :(得分:0)
软件包socket_io
与Flutter不兼容。因此,您不能在Flutter应用程序中使用它。