基础库
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

main.dart 7.3 KiB

4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import 'package:dio/dio.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_alibc/flutter_alibc.dart';
  4. import 'package:jdsdk/jdsdk.dart';
  5. import 'package:url_launcher/url_launcher.dart';
  6. import 'package:zhiying_comm/register.dart';
  7. import 'package:zhiying_comm/zhiying_comm.dart';
  8. import 'taobao_image_viewer.dart';
  9. void main() => runApp(MyApp());
  10. class MyApp extends StatefulWidget {
  11. @override
  12. _MyAppState createState() => _MyAppState();
  13. }
  14. class _MyAppState extends State<MyApp> {
  15. @override
  16. void initState() {
  17. BaseWidgetRegister.init();
  18. Jdsdk.init(
  19. appKey: '9fc3dec00b9b40cc950dfba5262cd6d3',
  20. appSecret: 'f785613e5fd54a129d0f0359a4e25c23')
  21. .then((result) {
  22. Logger.debug('京东初始化:${result.toString()}');
  23. });
  24. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  25. Logger.debug('${result.errorCode} ${result.errorMessage}');
  26. });
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return MaterialApp(
  32. home: HomePage(),
  33. );
  34. }
  35. }
  36. class HomePage extends StatelessWidget {
  37. netPost() async {
  38. dynamic result =
  39. await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  40. print("result === ${result?.toString()}");
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return Scaffold(
  45. appBar: AppBar(
  46. title: const Text('智莺-基础库'),
  47. ),
  48. body: SingleChildScrollView(
  49. child: Center(
  50. child: Wrap(
  51. spacing: 10,
  52. children: <Widget>[
  53. RaisedButton(
  54. onPressed: () {
  55. Navigator.push(context, MaterialPageRoute(builder: (_) {
  56. // return DeviceInfoPage();
  57. }));
  58. },
  59. child: Text('设备信息'),
  60. ),
  61. RaisedButton(
  62. onPressed: () {
  63. Navigator.push(context, MaterialPageRoute(builder: (_) {
  64. // return PackageInfoPage();
  65. }));
  66. },
  67. child: Text('应用信息'),
  68. ),
  69. RaisedButton(
  70. onPressed: () {
  71. NetUtil.post('/siteapi/v1/ucenter/login/', params: {
  72. 'username': 'xiangguohui',
  73. 'password': 'fnuo123com'
  74. });
  75. },
  76. child: Text('登录请求'),
  77. ),
  78. RaisedButton(
  79. onPressed: () {
  80. NetUtil.request('/api/v1/rec/featured?page=1', params: null,
  81. onError: (msg) {
  82. print('onERROR = ${msg?.toString() ?? 'onError'}');
  83. }, onSuccess: (json) {
  84. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  85. }, onCache: (json) {
  86. print('onCache = ${json?.toString() ?? 'onCache'}');
  87. });
  88. },
  89. child: Text('网络异步请求(带缓存)'),
  90. ),
  91. RaisedButton(
  92. onPressed: () {
  93. netPost();
  94. },
  95. child: Text('网络同步请求(无缓存)'),
  96. ),
  97. RaisedButton(
  98. onPressed: () {
  99. // LogUtil.test();
  100. },
  101. child: Text('显示日志'),
  102. ),
  103. RaisedButton(
  104. onPressed: () {
  105. Navigator.push(context, MaterialPageRoute(builder: (_) {
  106. return Logger();
  107. }));
  108. },
  109. child: Text('打开日志视图'),
  110. ),
  111. RaisedButton(
  112. onPressed: () {
  113. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  114. // onSuccess: (params){
  115. // Logger.log("onSuccess#$params");
  116. // },
  117. // onCache: (params){
  118. // Logger.log("onCache#$params");
  119. // });
  120. testPost();
  121. },
  122. child: Text('测试接口'),
  123. ),
  124. RaisedButton(
  125. onPressed: () {
  126. Navigator.push(context, MaterialPageRoute(builder: (_) {
  127. return TaobaoImageView();
  128. }));
  129. },
  130. child: Text('抓淘宝图片'),
  131. ),
  132. RaisedButton(
  133. onPressed: () {
  134. TaobaoAuth.auth(context);
  135. },
  136. child: Text('淘宝授权'),
  137. ),
  138. RaisedButton(
  139. onPressed: () {
  140. //
  141. Dio dio = Dio();
  142. dio.get(
  143. 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html')
  144. .then((value) {
  145. Logger.debug(value.realUri.toString());
  146. });
  147. },
  148. child: Text('获取重定向地址'),
  149. ),
  150. RaisedButton(
  151. onPressed: () {
  152. Jdsdk.openUrl(
  153. url: 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html');
  154. },
  155. child: Text('打开京东详情'),
  156. ),
  157. RaisedButton(
  158. onPressed: () async {
  159. String detailUrl = 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html';
  160. String baseUrl = detailUrl.getBaseUrl();
  161. if (!baseUrl.contains('jd.com')) {
  162. Dio dio = Dio();
  163. var responds = await dio.get(detailUrl);
  164. detailUrl = responds.realUri.toString();
  165. }
  166. Logger.debug(detailUrl);
  167. Jdsdk.openUrl(
  168. url
  169. :
  170. detailUrl
  171. );
  172. },
  173. child: Text('嗨如意转链打开京东'),
  174. ),
  175. RaisedButton(
  176. onPressed: () async {
  177. const url = 'weixin://';
  178. if (await canLaunch(url)) {
  179. await launch(url);
  180. } else {
  181. throw 'Could not launch $url';
  182. }
  183. },
  184. child: Text('url scheme打开app'),
  185. ),
  186. ],
  187. ),
  188. ),
  189. ),
  190. );
  191. }
  192. void testPost() async {
  193. var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {
  194. 'ids': [7]
  195. });
  196. print("cahced ${cached?.toString()}");
  197. var param = await NetUtil.post('/api/v1/mod',
  198. params: {
  199. 'ids': [7]
  200. },
  201. method: NetMethod.POST);
  202. print('apapapsdjfdsjf: ${param?.toString()}');
  203. }
  204. }