collect_page.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:liftmanager/internal/bbs/model/mix_model.dart';
  5. import 'package:liftmanager/internal/bbs/presenter/mix_list_presenter.dart';
  6. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  7. import 'package:liftmanager/mvp/base_page_state.dart';
  8. import 'package:liftmanager/utils/fast_notification.dart';
  9. import 'package:liftmanager/widgets/app_bar.dart';
  10. import 'package:liftmanager/widgets/bbs_content.dart';
  11. import 'package:liftmanager/widgets/my_refresh_list.dart';
  12. import 'package:liftmanager/widgets/state_layout.dart';
  13. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  14. import 'package:provider/provider.dart';
  15. class CollectPage extends StatefulWidget {
  16. String index = "1";
  17. @override
  18. CollectPageState createState() => CollectPageState();
  19. }
  20. class CollectPageState extends BasePageState<CollectPage, MixListPresenter> {
  21. // NewsDetailItem item = NewsDetailItem();
  22. BaseListProvider<Records> provider = BaseListProvider<Records>();
  23. int checkIndex = 0;
  24. int _page = 1;
  25. List<String> titleList = [
  26. // "全部",
  27. "问答",
  28. "视频",
  29. "职位",
  30. "商品",
  31. ];
  32. @override
  33. void initState() {
  34. provider.setStateTypeNotNotify(StateType.loading);
  35. super.initState();
  36. _onRefresh();
  37. FastNotification.addListener("collectAction", (collectInit) {
  38. if (mounted) {
  39. setState(() {});
  40. _onRefresh();
  41. }
  42. });
  43. }
  44. @override
  45. void didChangeDependencies() {
  46. super.didChangeDependencies();
  47. print(12366);
  48. }
  49. @override
  50. void deactivate() {
  51. super.deactivate();
  52. print(123667);
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. double width = MediaQuery.of(context).size.width;
  57. return Scaffold(
  58. appBar: MyAppBar(
  59. centerTitle: "我的收藏",
  60. ),
  61. body: Container(
  62. child: Stack(
  63. children: <Widget>[
  64. Positioned(
  65. child: Container(
  66. padding: EdgeInsets.only(bottom: 5),
  67. // color:Color(0xffFAF7FA),
  68. decoration: BoxDecoration(
  69. border: Border(
  70. bottom: BorderSide(width: 0.5, color: Color(0xffeeeeee)),
  71. ),
  72. // color: Color(0xffffffff),
  73. ),
  74. child: Row(
  75. mainAxisAlignment: MainAxisAlignment.spaceAround,
  76. children: titleList.asMap().keys.map((i) {
  77. return TabThis(
  78. item: titleList[i],
  79. tabIndex: i,
  80. checkIndex: checkIndex,
  81. fun: () {
  82. provider.list.clear();
  83. setState(() {
  84. checkIndex = i;
  85. });
  86. provider.setStateTypeNotNotify(StateType.loading);
  87. _onRefresh();
  88. print(checkIndex);
  89. });
  90. }).toList())),
  91. ),
  92. Container(
  93. child: ChangeNotifierProvider<BaseListProvider<Records>>(
  94. create: (_) => provider,
  95. child: Column(
  96. children: <Widget>[
  97. SizedBox(height: ScreenUtil().setWidth(50)),
  98. Expanded(
  99. flex: 1,
  100. child: Consumer<BaseListProvider<Records>>(
  101. builder: (_, provider, __) {
  102. return MyListView(
  103. key: Key('mix_list'),
  104. showSeparator: checkIndex == 0,
  105. itemCount: provider.list.length,
  106. stateType: provider.stateType,
  107. onRefresh: _onRefresh,
  108. loadMore: _loadMore,
  109. hasMore: provider.hasMore,
  110. padding: EdgeInsets.symmetric(horizontal: 10),
  111. itemBuilder: (_, index) {
  112. return Column(
  113. crossAxisAlignment:
  114. CrossAxisAlignment.start,
  115. children: <Widget>[
  116. checkIndex == 0
  117. ? QuestionCell(
  118. item: provider.list[index])
  119. : Container(child: null),
  120. checkIndex == 1
  121. ? VideoCell(provider.list[index])
  122. : Container(child: null),
  123. checkIndex == 2
  124. ? PositionCell(provider.list[index])
  125. : Container(child: null),
  126. checkIndex == 3
  127. ? ProductCell(provider.list[index])
  128. : Container(child: null),
  129. ],
  130. );
  131. },
  132. );
  133. }))
  134. ],
  135. )))
  136. ],
  137. )));
  138. }
  139. Future _onRefresh() async {
  140. _page = 1;
  141. if (checkIndex == 0) {
  142. await presenter.getQuestionList(_page);
  143. } else if (checkIndex == 1) {
  144. await presenter.getVideoList(_page);
  145. } else if (checkIndex == 2) {
  146. await presenter.getPositionList(_page);
  147. } else if (checkIndex == 3) {
  148. await presenter.getShopList(_page);
  149. }
  150. }
  151. Future _loadMore() async {
  152. _page++;
  153. if (checkIndex == 0) {
  154. await presenter.getQuestionList(_page);
  155. } else if (checkIndex == 1) {
  156. await presenter.getVideoList(_page);
  157. } else if (checkIndex == 2) {
  158. await presenter.getPositionList(_page);
  159. } else if (checkIndex == 3) {
  160. await presenter.getShopList(_page);
  161. }
  162. }
  163. @override
  164. MixListPresenter createPresenter() {
  165. return MixListPresenter();
  166. }
  167. }
  168. class TabThis extends StatelessWidget {
  169. TabThis({Key key, this.item, this.tabIndex, this.fun, this.checkIndex})
  170. : super(key: key);
  171. String item;
  172. int tabIndex;
  173. int checkIndex;
  174. Function fun;
  175. @override
  176. Widget build(BuildContext context) {
  177. return Container(
  178. padding: EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  179. child: Container(
  180. child: Row(
  181. mainAxisAlignment: MainAxisAlignment.center,
  182. children: <Widget>[
  183. GestureDetector(
  184. onTap: () {
  185. fun();
  186. },
  187. child: Container(
  188. padding: EdgeInsets.only(bottom: 6),
  189. decoration: BoxDecoration(
  190. border: Border(
  191. bottom: BorderSide(
  192. width: 2,
  193. color: checkIndex == tabIndex
  194. ? Color(0xff02A0FD)
  195. : Colors.transparent),
  196. ),
  197. // color: Color(0xff9FD1FE),
  198. ),
  199. child: Text(
  200. item,
  201. style: TextStyle(
  202. color: checkIndex == tabIndex
  203. ? Color(0xff02A0FD)
  204. : Color(0xff666666),
  205. fontSize: ScreenUtil().setSp(14)),
  206. textAlign: TextAlign.center,
  207. ),
  208. ))
  209. ])),
  210. );
  211. }
  212. }