基础库
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main.dart 8.1 KiB

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