index.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import 'package:flutter/material.dart';
  2. import 'package:fun_selfie_app/pages/home/setting.dart';
  3. import 'package:fun_selfie_app/pages/home/search_bar.dart';
  4. import 'package:fun_selfie_app/utils/api.dart';
  5. import 'package:fun_selfie_app/widgets/my_refresh_list.dart';
  6. class HomePage extends StatefulWidget {
  7. const HomePage({Key? key}) : super(key: key);
  8. @override
  9. State<StatefulWidget> createState() => _HomePageState();
  10. }
  11. class _HomePageState extends State<HomePage> {
  12. bool isUp = false;
  13. int currentPage = 1;
  14. int totalPage = 0;
  15. final ScrollController _controller = ScrollController();
  16. // List listData = [];
  17. @override
  18. void initState() {
  19. super.initState();
  20. // 初始化的时候开启倒计时
  21. getList();
  22. // _controller.addListener(() {
  23. // if (_controller.position.pixels >
  24. // _controller.position.maxScrollExtent - 40) {
  25. // onRefresh();
  26. // }
  27. // });
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: AppBar(title: const Text('趣味自拍'), actions: <Widget>[
  33. TextButton.icon(
  34. icon: Icon(
  35. isUp ? Icons.vertical_align_top : Icons.vertical_align_bottom,
  36. color: Colors.white,
  37. size: 32,
  38. ),
  39. label: const Text(
  40. '排序 活动时间',
  41. style: TextStyle(color: Colors.white, fontSize: 20),
  42. ),
  43. onPressed: () {
  44. setState(() {
  45. isUp = !isUp;
  46. });
  47. },
  48. ),
  49. Padding(
  50. padding: const EdgeInsets.only(left: 30, right: 30),
  51. child: TextButton(
  52. child: const Text(
  53. '创建',
  54. style: TextStyle(color: Colors.white, fontSize: 20),
  55. ),
  56. onPressed: () {
  57. Navigator.pushNamed(context, "/addNews");
  58. })),
  59. Padding(
  60. padding: const EdgeInsets.only(right: 30),
  61. child: IconButton(
  62. icon: const Icon(Icons.search),
  63. onPressed: () {
  64. showSearch(context: context, delegate: SeachBarDelegate());
  65. },
  66. )),
  67. ]),
  68. body: Scrollbar(
  69. // thumbVisibility: true,
  70. controller: _controller,
  71. child: DeerListView(
  72. controller: _controller,
  73. onRefresh: onRefresh,
  74. hasMore: currentPage < totalPage,
  75. loadMore: onRefresh,
  76. itemCount: listData.length, //条目个数:获取数据的个数
  77. itemBuilder: (context, index) {
  78. return GestureDetector(
  79. onTap: () {
  80. Navigator.pushNamed(
  81. context, "/newsDetail/${listData[index]["id"]}");
  82. },
  83. child: Column(
  84. crossAxisAlignment: CrossAxisAlignment.start,
  85. children: [
  86. Container(
  87. padding:
  88. const EdgeInsets.only(left: 12, right: 12, top: 10),
  89. child: Text(listData[index]["createTime"],
  90. style: const TextStyle(
  91. fontSize: 16,
  92. overflow: TextOverflow.ellipsis,
  93. ))),
  94. ListTile(
  95. title: Text(listData[index]["title"]),
  96. subtitle: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. const SizedBox(height: 12),
  100. Text(listData[index]["subtitle"],
  101. style: const TextStyle(
  102. fontSize: 12, color: Colors.grey)),
  103. ],
  104. ), //小标题
  105. // trailing: Image.network(listData[index]["image"],
  106. // fit: BoxFit.fill, width: 110, height: 90),
  107. // visualDensity:
  108. // const VisualDensity(vertical: 4), //增加item高度,优化布局,便于图片展示
  109. minVerticalPadding: 8,
  110. )
  111. ]),
  112. );
  113. },
  114. ),
  115. ),
  116. drawer: const Drawer(
  117. child: DrawerModalPage(),
  118. ),
  119. );
  120. }
  121. List listData = [
  122. {
  123. 'id': '0001',
  124. "title": "斗门希尔顿「林俭华&魏映雪」婚礼直播",
  125. "subtitle": "珠海",
  126. "image":
  127. "https://img-blog.csdnimg.cn/c6dfd375abf1433fa3a42951cc186a2b.jpeg",
  128. 'createTime': '2023年6月02日',
  129. },
  130. {
  131. 'id': '0002',
  132. "title": "嘉德诺家庭日",
  133. "subtitle": "上海",
  134. "image":
  135. "https://img-blog.csdnimg.cn/678c0686dc694b65ad6b20693dbc35f1.jpeg",
  136. 'createTime': '2023年5月16日',
  137. },
  138. {
  139. 'id': '0003',
  140. "title": "祥琪酒店「梁培安&丘凤」婚礼直播",
  141. "subtitle": "上海",
  142. "image":
  143. "https://img-blog.csdnimg.cn/63efe7acbac74e7ebce85e3801f948e3.jpeg",
  144. 'createTime': '2023年5月02日',
  145. },
  146. {
  147. 'id': '0004',
  148. "title": "黄府寿宴--广州华南理工大学西湖苑宾馆",
  149. "subtitle": "广州",
  150. "image":
  151. "https://img-blog.csdnimg.cn/c6dfd375abf1433fa3a42951cc186a2b.jpeg",
  152. 'createTime': '2023年4月30日',
  153. },
  154. {
  155. 'id': '0005',
  156. "title": "西卡德高广州总部大厦乔迁庆典",
  157. "subtitle": "广州",
  158. "image":
  159. "https://img-blog.csdnimg.cn/678c0686dc694b65ad6b20693dbc35f1.jpeg",
  160. 'createTime': '2023年4月15日',
  161. },
  162. {
  163. 'id': '0006',
  164. "title": "郭鹏&欧阳思昐 新婚之喜",
  165. "subtitle": "广州",
  166. "image":
  167. "https://img-blog.csdnimg.cn/63efe7acbac74e7ebce85e3801f948e3.jpeg",
  168. 'createTime': '2023年4月02日',
  169. },
  170. {
  171. 'id': '0007',
  172. "title": "深圳宝安格兰云天",
  173. "subtitle": "广州",
  174. "image":
  175. "https://img-blog.csdnimg.cn/c6dfd375abf1433fa3a42951cc186a2b.jpeg",
  176. 'createTime': '20201232',
  177. },
  178. {
  179. 'id': '0008',
  180. "title": "祥琪酒店「梁培安&丘凤」婚礼直播",
  181. "subtitle": "上海",
  182. "image":
  183. "https://img-blog.csdnimg.cn/c6dfd375abf1433fa3a42951cc186a2b.jpeg",
  184. 'createTime': '2023年5月24日',
  185. },
  186. {
  187. 'id': '0009',
  188. "title": "西卡德高广州总部大厦乔迁庆典",
  189. "subtitle": "上海",
  190. "image":
  191. "https://img-blog.csdnimg.cn/c6dfd375abf1433fa3a42951cc186a2b.jpeg",
  192. 'createTime': '2023年5月12日',
  193. },
  194. ];
  195. Future<dynamic> getList() async {
  196. try {
  197. // var params = {
  198. // "pageNo": currentPage,
  199. // "pageSize": 20,
  200. // "status": 'DONE', //READY
  201. // "saleOrderNo": ''
  202. // };
  203. // var res = await UtilHelper.updateList(params);
  204. var params = {
  205. "pageNo": currentPage,
  206. "pageSize": 30,
  207. "department": 'PACKING',
  208. "worklineId": 'workline-1-packing',
  209. "end": false
  210. };
  211. var res = await UtilHelper.updatePackingList(params);
  212. setState(() {
  213. // if (currentPage > 1) {
  214. // listData.addAll(res['records']);
  215. // } else {
  216. // listData = res['records'];
  217. // }
  218. // totalPage = res['pages'];
  219. });
  220. } catch (err) {
  221. debugPrint(err.toString());
  222. }
  223. }
  224. /// 处理刷新操作
  225. Future onRefresh() async {
  226. await Future.delayed(const Duration(seconds: 1), () {
  227. ++currentPage;
  228. getList();
  229. });
  230. }
  231. }