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

116 line
3.2 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 = 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. ],
  102. ),
  103. ),
  104. );
  105. }
  106. }