基础库
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.

main.dart 4.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 = await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  31. print("result === ${result?.toString()}");
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return SingleChildScrollView(
  36. child: Center(
  37. child: Column(
  38. crossAxisAlignment: CrossAxisAlignment.center,
  39. mainAxisAlignment: MainAxisAlignment.center,
  40. children: <Widget>[
  41. RaisedButton(
  42. onPressed: () {
  43. Navigator.push(context, MaterialPageRoute(builder: (_) {
  44. return DeviceInfoPage();
  45. }));
  46. },
  47. child: Text('设备信息'),
  48. ),
  49. RaisedButton(
  50. onPressed: () {
  51. Navigator.push(context, MaterialPageRoute(builder: (_) {
  52. return PackageInfoPage();
  53. }));
  54. },
  55. child: Text('应用信息'),
  56. ),
  57. RaisedButton(
  58. onPressed: () {
  59. NetUtil.post('/siteapi/v1/ucenter/login/', params: {
  60. 'username': 'xiangguohui',
  61. 'password': 'fnuo123com'
  62. });
  63. },
  64. child: Text('登录请求'),
  65. ),
  66. RaisedButton(
  67. onPressed: () {
  68. NetUtil.request('/api/v1/rec/featured?page=1', params: null,
  69. onError: (msg) {
  70. print('onERROR = ${msg?.toString() ?? 'onError'}');
  71. }, onSuccess: (json) {
  72. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  73. }, onCache: (json) {
  74. print('onCache = ${json?.toString() ?? 'onCache'}');
  75. });
  76. },
  77. child: Text('网络异步请求(带缓存)'),
  78. ),
  79. RaisedButton(
  80. onPressed: () {
  81. netPost();
  82. },
  83. child: Text('网络同步请求(无缓存)'),
  84. ),
  85. RaisedButton(
  86. onPressed: (){
  87. LogUtil.test();
  88. },
  89. child: Text('显示日志'),
  90. ),
  91. RaisedButton(
  92. onPressed: (){
  93. Navigator.push(context, MaterialPageRoute(
  94. builder: (_){
  95. return Logger();
  96. }
  97. ));
  98. },
  99. child: Text('打开日志视图'),
  100. ),
  101. RaisedButton(
  102. onPressed: (){
  103. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  104. // onSuccess: (params){
  105. // Logger.log("onSuccess#$params");
  106. // },
  107. // onCache: (params){
  108. // Logger.log("onCache#$params");
  109. // });
  110. testPost();
  111. },
  112. child: Text('测试接口'),
  113. ),
  114. ],
  115. ),
  116. ),
  117. );
  118. }
  119. void testPost() async{
  120. var cached = await NetUtil.getRequestCachedData( '/api/v1/mod', params: {'ids': [7] });
  121. print("cahced ${cached?.toString()}");
  122. var param = await NetUtil.post('/api/v1/mod', params: {'ids': [7] }, method: NetMethod.POST);
  123. print('apapapsdjfdsjf: ${param?.toString()}');
  124. }
  125. }