基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

171 lines
5.3 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_comm/zhiying_comm.dart';
  3. // import 'package:zhiying_comm_example/device_info_page.dart';
  4. // import 'package:zhiying_comm_example/log_util.dart';
  5. // import 'package:zhiying_comm_example/package_info_page.dart';
  6. void main() => runApp(MyApp());
  7. class MyApp extends StatefulWidget {
  8. @override
  9. _MyAppState createState() => _MyAppState();
  10. }
  11. class _MyAppState extends State<MyApp> {
  12. @override
  13. void initState() {
  14. super.initState();
  15. }
  16. @override
  17. Widget build(BuildContext context) {
  18. return MaterialApp(
  19. home: Scaffold(
  20. appBar: AppBar(
  21. title: const Text('智莺-基础库'),
  22. ),
  23. body: HomePage(),
  24. ),
  25. );
  26. }
  27. }
  28. class HomePage extends StatelessWidget {
  29. netPost() async {
  30. dynamic result =
  31. await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  32. print("result === ${result?.toString()}");
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return SingleChildScrollView(
  37. child: Center(
  38. child: Column(
  39. crossAxisAlignment: CrossAxisAlignment.center,
  40. mainAxisAlignment: MainAxisAlignment.center,
  41. children: <Widget>[
  42. RaisedButton(
  43. onPressed: () {
  44. Navigator.push(context, MaterialPageRoute(builder: (_) {
  45. // return DeviceInfoPage();
  46. }));
  47. },
  48. child: Text('设备信息'),
  49. ),
  50. RaisedButton(
  51. onPressed: () {
  52. Navigator.push(context, MaterialPageRoute(builder: (_) {
  53. // return PackageInfoPage();
  54. }));
  55. },
  56. child: Text('应用信息'),
  57. ),
  58. RaisedButton(
  59. onPressed: () {
  60. NetUtil.post('/siteapi/v1/ucenter/login/', params: {
  61. 'username': 'xiangguohui',
  62. 'password': 'fnuo123com'
  63. });
  64. },
  65. child: Text('登录请求'),
  66. ),
  67. RaisedButton(
  68. onPressed: () {
  69. NetUtil.request('/api/v1/rec/featured?page=1', params: null,
  70. onError: (msg) {
  71. print('onERROR = ${msg?.toString() ?? 'onError'}');
  72. }, onSuccess: (json) {
  73. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  74. }, onCache: (json) {
  75. print('onCache = ${json?.toString() ?? 'onCache'}');
  76. });
  77. },
  78. child: Text('网络异步请求(带缓存)'),
  79. ),
  80. RaisedButton(
  81. onPressed: () {
  82. netPost();
  83. },
  84. child: Text('网络同步请求(无缓存)'),
  85. ),
  86. RaisedButton(
  87. onPressed: () {
  88. // LogUtil.test();
  89. },
  90. child: Text('显示日志'),
  91. ),
  92. RaisedButton(
  93. onPressed: () {
  94. Navigator.push(context, MaterialPageRoute(builder: (_) {
  95. return Logger();
  96. }));
  97. },
  98. child: Text('打开日志视图'),
  99. ),
  100. RaisedButton(
  101. onPressed: () {
  102. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  103. // onSuccess: (params){
  104. // Logger.log("onSuccess#$params");
  105. // },
  106. // onCache: (params){
  107. // Logger.log("onCache#$params");
  108. // });
  109. testPost();
  110. },
  111. child: Text('测试接口'),
  112. ),
  113. RaisedButton(
  114. onPressed: () async {
  115. Api api = Api('/api/v1/user/info', method: NetMethod.GET);
  116. // api.onCache().then((cache) {
  117. // print('读取缓存 ${cache.toString()}');
  118. // return api.onRequest();
  119. // }).then((result) {
  120. // print('网络请求 ${result.toString().length}');
  121. // }).catchError((error) {
  122. // print('aaaa');
  123. // print('error: ${error.toString()}');
  124. // });
  125. var cache = await api.onCache();
  126. var result = await api.onRequest();
  127. },
  128. child: Text('新网络请求'),
  129. ),
  130. RaisedButton(
  131. onPressed: () {
  132. Navigator.push(context, MaterialPageRoute(builder: (_) {
  133. return TaobaoImageLoader(
  134. 'https://h5.m.taobao.com/app/detail/desc.html?_isH5Des=true#!id=592787622422&type=1&f=&sellerType=B',
  135. onImagesLoad: (images) {
  136. Logger.debug(images.toString());
  137. },
  138. );
  139. }));
  140. // TaobaoUtil.getImage();
  141. },
  142. child: Text('抓淘宝图片'),
  143. ),
  144. ],
  145. ),
  146. ),
  147. );
  148. }
  149. void testPost() async {
  150. var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {
  151. 'ids': [7]
  152. });
  153. print("cahced ${cached?.toString()}");
  154. var param = await NetUtil.post('/api/v1/mod',
  155. params: {
  156. 'ids': [7]
  157. },
  158. method: NetMethod.POST);
  159. print('apapapsdjfdsjf: ${param?.toString()}');
  160. }
  161. }