better_socket 1.0.0 better_socket: ^1.0.0 copied to clipboard
这是一个集成原生iOS的websocket和安卓原生的websocket,力争做一个完美的websocket插件。有人反映dart的websocket配置很麻烦,就是做这个插件的初衷。
better_socket #
A new flutter plugin project.
Getting Started #
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
使用 #
import 'package:flutter/material.dart';
import 'package:better_socket/better_socket.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _msg = "";
@override
void initState() {
super.initState();
// 初始化socket
BetterSocket.connentSocket("ws://123.207.167.163:9010/ajaxchattest")
.then((val) {
// print(val);
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
RaisedButton(
child: Text('发送消息'),
onPressed: () {
// 发送消息
BetterSocket.sendMsg("hello").then((msg) {
setState(() {
_msg = msg;
});
});
},
),
Text(_msg)
],
),
),
);
}
@override
void dispose() {
BetterSocket.close();
super.dispose();
}
}
# Todo 安卓还没有接入