基础库
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

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