Hibok
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

306 satır
9.1 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:chat/generated/i18n.dart';
  3. import 'package:chat/home/AddProgram.dart';
  4. import 'package:chat/utils/CustomUI.dart';
  5. import 'package:chat/utils/MessageBox.dart';
  6. import 'package:chat/utils/MessageMgr.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:chat/utils/PopUpMenu.dart' as myPop;
  9. import 'package:oktoast/oktoast.dart';
  10. import 'package:pull_to_refresh/pull_to_refresh.dart';
  11. import '../utils/HttpUtil.dart';
  12. import 'package:dio/dio.dart';
  13. import "../data/UserData.dart";
  14. import '../utils/TokenMgr.dart';
  15. class MyProgramPage extends StatefulWidget {
  16. @required
  17. final bool isProgram;
  18. @required
  19. final bool isMan;
  20. final userId;
  21. MyProgramPage(
  22. {Key key, this.isProgram = true, this.userId, this.isMan = false})
  23. : super(key: key);
  24. @override
  25. _MyProgramPageState createState() => new _MyProgramPageState();
  26. }
  27. class _MyProgramPageState extends State<MyProgramPage> {
  28. List list = new List(); //列表要展示的数据
  29. RefreshController _refreshController =
  30. RefreshController(initialRefresh: true);
  31. int _page = 1; //加载的页数
  32. int rows = 20;
  33. bool isMyself = false;
  34. addProgramCallback(data) {
  35. list.insert(0, data);
  36. }
  37. @override
  38. void initState() {
  39. isMyself = widget.userId == UserData().basicInfo.userId;
  40. super.initState();
  41. MessageMgr().on('delete_program', msgListDelete);
  42. MessageMgr().on('Add_program', addProgramCallback);
  43. MessageMgr().on('refresh_list', msgRefreshList);
  44. MessageMgr().on('join_program', msgJoinList);
  45. }
  46. msgJoinList(data) {
  47. for (int i = 0; i < list.length; i++) {
  48. if (list[i]['Id'] == data) {
  49. list[i]['EnrollNum']++;
  50. list[i]['IsEnroll']++;
  51. setState(() {});
  52. break;
  53. }
  54. }
  55. }
  56. msgRefreshList(data) {
  57. _onRefresh();
  58. }
  59. msgListLove(data) {
  60. for (int i = 0; i < list.length; i++) {
  61. if (list[i]['Id'] == data) {
  62. list[i]['FabulousNum']++;
  63. list[i]['IsFabulous']++;
  64. setState(() {});
  65. break;
  66. }
  67. }
  68. }
  69. msgListDelete(data) {
  70. for (int i = 0; i < list.length; i++) {
  71. if (list[i]['Id'] == data) {
  72. list.removeAt(i);
  73. setState(() {});
  74. break;
  75. }
  76. }
  77. }
  78. Future getData(callback) async {
  79. var data = {
  80. "userId": UserData().basicInfo.userId,
  81. "visitUserId": widget.userId,
  82. //"type": widget.isProgram == true ? 1 : 2,
  83. };
  84. data['sign'] = TokenMgr().getSign(data);
  85. data['page'] = _page;
  86. data['rows'] = rows;
  87. Response res = await HttpUtil().post('station/gain/program',
  88. data: data, failback: () => Navigator.of(context).pop());
  89. _refreshController.refreshCompleted();
  90. var resData = res.data;
  91. if (resData['code'] == 0) {
  92. callback(resData['data']);
  93. } else {
  94. showToast(resData['msg']);
  95. }
  96. }
  97. void addProgram(str) async {
  98. if (str == 'program') {
  99. //自己是女性,且未认证,提示去认证
  100. if (!UserData().isMan() && !UserData().basicInfo.isAttestation) {
  101. CustomUI.buildNotTrue(context);
  102. return;
  103. }
  104. if (!UserData().isCanProgram) {
  105. showToast(I18n.of(context).stop_program);
  106. } else {
  107. Navigator.of(context).push(
  108. new MaterialPageRoute(
  109. builder: (context) {
  110. return AddProgram(
  111. isProgram: true,
  112. );
  113. },
  114. ),
  115. );
  116. }
  117. } else if (str == 'dynamic') {
  118. //自己是女性,且未认证,提示去认证
  119. if (!UserData().isMan() && !UserData().basicInfo.isAttestation) {
  120. CustomUI.buildNotTrue(context);
  121. return;
  122. }
  123. Navigator.of(context).push(
  124. new MaterialPageRoute(
  125. builder: (context) {
  126. return AddProgram(
  127. isProgram: false,
  128. );
  129. },
  130. ),
  131. );
  132. }
  133. }
  134. @override
  135. Widget build(BuildContext context) {
  136. Widget appBar = new AppBar(
  137. backgroundColor: AppColors.NewAppbarBgColor,
  138. title: new Text(
  139. // widget.isProgram
  140. // ? (isMyself
  141. // ? I18n.of(context).my_show
  142. // : (widget.isMan
  143. // ? I18n.of(context).his_dynamics
  144. // : I18n.of(context).her_dynamics))
  145. // : (isMyself
  146. // ? I18n.of(context).my_dynamic
  147. // : (widget.isMan
  148. // ? I18n.of(context).his_dynamics
  149. // : I18n.of(context).her_dynamics)),
  150. isMyself
  151. ? I18n.of(context).my_dynamic
  152. : (widget.isMan
  153. ? I18n.of(context).his_dynamics
  154. : I18n.of(context).her_dynamics),
  155. textScaleFactor: 1.0,
  156. style: TextStyle(color: AppColors.NewAppbarTextColor),
  157. ),
  158. centerTitle: true,
  159. leading: CustomUI.buildCustomLeading(context),
  160. actions: <Widget>[
  161. isMyself
  162. ? myPop.PopupMenuButton<String>(
  163. padding: EdgeInsets.zero,
  164. offset: Offset(0, 45),
  165. child: Container(
  166. alignment: Alignment.center,
  167. child: new Padding(
  168. padding: EdgeInsets.only(
  169. right: 15, left: 15, top: 10, bottom: 10),
  170. child: new Text(
  171. I18n.of(context).release,
  172. textScaleFactor: 1.0,
  173. style: Constants.AppBarActionTextStyle,
  174. ),
  175. ),
  176. ),
  177. onSelected: (str) {
  178. addProgram(str);
  179. },
  180. itemBuilder: (BuildContext context) =>
  181. <myPop.PopupMenuEntry<String>>[
  182. myPop.PopupMenuItem<String>(
  183. value: 'program',
  184. child: Container(
  185. margin: EdgeInsets.only(top: 15, bottom: 15),
  186. child: Text(
  187. I18n.of(context).release_program,
  188. textScaleFactor: 1.0,
  189. textAlign: TextAlign.center,
  190. ),
  191. )),
  192. myPop.PopupMenuDivider(
  193. height: 1,
  194. ),
  195. myPop.PopupMenuItem<String>(
  196. value: 'dynamic',
  197. child: Container(
  198. margin: EdgeInsets.only(top: 15, bottom: 15),
  199. child: Text(
  200. I18n.of(context).release_dynamics,
  201. textScaleFactor: 1.0,
  202. textAlign: TextAlign.center,
  203. )),
  204. ),
  205. ],
  206. )
  207. : Container()
  208. ],
  209. );
  210. Widget content = Scaffold(
  211. appBar: appBar,
  212. body: SafeArea(
  213. child: SmartRefresher(
  214. enablePullDown: true,
  215. enablePullUp: true,
  216. header: MaterialClassicHeader(),
  217. footer: CustomUI.buildLoadingFooter(),
  218. controller: _refreshController,
  219. onRefresh: _onRefresh,
  220. onLoading: _onLoading,
  221. child: (_refreshController.headerStatus == RefreshStatus.completed &&
  222. list.length == 0)
  223. ? CustomUI.buildNoData(context)
  224. : ListView.builder(
  225. itemBuilder: _renderRow,
  226. itemCount: list.length,
  227. ),
  228. )),
  229. );
  230. return content;
  231. }
  232. Widget _renderRow(BuildContext context, int index) {
  233. // if (list.length == 0) {
  234. // return CustomUI.buildNoData(
  235. // context,
  236. // str: isMyself
  237. // ? (widget.isProgram
  238. // ? I18n.of(context).no_program
  239. // : I18n.of(context).on_dynamic)
  240. // : (widget.isMan
  241. // ? I18n.of(context).low_key2
  242. // : I18n.of(context).low_key),
  243. // );
  244. // }
  245. if (index < list.length) {
  246. var userInfo = list[index];
  247. print('--------------------------------------------');
  248. print(userInfo);
  249. return MessageBox(
  250. programInfo: userInfo,
  251. );
  252. }
  253. return Container();
  254. }
  255. Future<Null> _onRefresh() async {
  256. _page = 1;
  257. getData((data) {
  258. list.clear();
  259. if (data != null) {
  260. list.addAll(data);
  261. }
  262. setState(() {});
  263. });
  264. }
  265. Future _onLoading() async {
  266. _page++;
  267. getData((data) {
  268. if (data == null || data.length == 0) {
  269. _page--;
  270. _refreshController.loadNoData();
  271. } else {
  272. list.addAll(data);
  273. _refreshController.loadComplete();
  274. }
  275. setState(() {});
  276. });
  277. }
  278. @override
  279. void dispose() {
  280. _refreshController.dispose();
  281. MessageMgr().off('delete_program', msgListDelete);
  282. MessageMgr().off('Add_program', addProgramCallback);
  283. MessageMgr().off('refresh_list', msgRefreshList);
  284. MessageMgr().off('join_program', msgJoinList);
  285. super.dispose();
  286. }
  287. }