yunceng_flutter_plugin 0.0.2
yunceng_flutter_plugin: ^0.0.2 copied to clipboard
The yunceng_flutter_plugin is a flutter plugin of yun ceng
import 'package:flutter/material.dart';
import 'package:yunceng_flutter_plugin/yunceng_flutter_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _initState = '';
String _proxyInfo = '';
@override
void initState() {
super.initState();
}
void _ycInit() async {
String msg;
try {
// 控制台对应的appkey,可咨询阿里云运营人员获取
String appKey = 'xxxxxxxxxxxx';
// 玩家账户信息,如玩家ID
String token = 'xunxiu';
int ret = await YuncengFlutterPlugin.initEx(appKey, token);
msg = "$ret";
} on Exception catch(e) {
msg = "init failed:'${e.toString()}'";
}
debugPrint(msg);
if(!mounted) return;
setState(() {
_initState = msg;
});
}
void _ycGetProxy() async {
String msg;
try {
// 玩家账户信息,如玩家ID
String token = 'xunxiu';
// 控制台上配置的用户分组ID,可咨询阿里云运营人员获取
String groupName = 'xxxxxxxxxxxxxxx';
// 防护目标domain,可咨询阿里云运营人员获取
String domain = 'yyyyyyyy';
// 防护端口
String port = '12345';
YuncengResult result = await YuncengFlutterPlugin.getProxyTcpByDomain(token, groupName, domain, port);
msg = "{ret:${result.ret}, ip:${result.ip}, port:${result.port}}";
} on Exception catch(e) {
msg = "get proxy failed:'${e.toString()}'";
}
debugPrint(msg);
if(!mounted) return;
setState(() {
_proxyInfo = msg;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('yunceng example app'),
),
body: Center(
child: Column(
children: <Widget>[
Text(
'yun cheng sdk',
style: Theme.of(context).textTheme.headline5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children:<Widget>[
ElevatedButton(
child: const Text('init'),
onPressed: _ycInit,
),
ElevatedButton(
child: const Text('proxy'),
onPressed: _ycGetProxy,
),
]
),
Text(
'init: $_initState',
),
Text(
'proxy: $_proxyInfo',
),
],
),
),
),
);
}
}