lysocket 0.0.2 lysocket: ^0.0.2 copied to clipboard
lysocket is a socket client.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:lysocket/lysocket.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
connect();
Lysocket.receiving();
Lysocket.setCallBack(this.test);
}
Future<void> sendMsg(String message) async {
String result = await Lysocket.sendMsg(message);
print(result);
}
Future<void> connect() async {
String result = await Lysocket.connect("192.168.0.110", 5566);
print(result);
}
test(String str){
print("==========>$str");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Container(
padding: EdgeInsets.all(10),
child: new TextField(
decoration: InputDecoration(
labelText: "输入要发送的内容",
labelStyle: TextStyle(color: Colors.blue, fontSize: 14),
),
onSubmitted: (val){
sendMsg(val);
},
),
),
),
);
}
}