基础库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

229 satır
7.7 KiB

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