Hibok
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.
 
 
 
 
 
 

484 lines
17 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/conversation.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/home/InfoList.dart';
  6. import 'package:chat/home/last_chat_record_widget.dart';
  7. import 'package:chat/home/rich_title.dart';
  8. import 'package:chat/home/unread_dot_widget.dart';
  9. import 'package:chat/utils/CustomUI.dart';
  10. import 'package:chat/utils/HttpUtil.dart';
  11. import 'package:chat/utils/MessageMgr.dart';
  12. import 'package:chat/utils/TokenMgr.dart';
  13. import 'package:dio/dio.dart';
  14. import 'package:flutter/cupertino.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:shared_preferences/shared_preferences.dart';
  17. import '../data/constants.dart' show AppColors, AppStyles, Constants;
  18. import 'package:cached_network_image/cached_network_image.dart';
  19. class _ConversationItem extends StatelessWidget {
  20. const _ConversationItem(
  21. {Key key,
  22. this.conversation,
  23. this.callback,
  24. this.icon,
  25. this.bgColor,
  26. this.iconSize = 20})
  27. : assert(conversation != null),
  28. super(key: key);
  29. final icon;
  30. final double iconSize;
  31. final Conversation conversation;
  32. final callback;
  33. final bgColor;
  34. @override
  35. Widget build(BuildContext context) {
  36. Widget avatar;
  37. if (icon != null) {
  38. avatar = Container(
  39. height: 47.5,
  40. width: 47.5,
  41. margin: EdgeInsets.only(left: 6),
  42. alignment: Alignment.center,
  43. decoration: BoxDecoration(
  44. gradient: bgColor,
  45. borderRadius: BorderRadius.all(Radius.circular(50))),
  46. child: Image.asset(
  47. icon,
  48. height: iconSize,
  49. ));
  50. } else if (conversation.isAvatarFromNet()) {
  51. avatar = CachedNetworkImage(
  52. imageUrl: conversation.avatar,
  53. placeholder: CustomUI.buildImgLoding,
  54. width: Constants.ConversationAvatarSize,
  55. height: Constants.ConversationAvatarSize,
  56. );
  57. } else {
  58. avatar = Image.asset(
  59. conversation.avatar,
  60. width: Constants.ConversationAvatarSize,
  61. height: Constants.ConversationAvatarSize,
  62. );
  63. }
  64. List<Widget> _rightArea = [
  65. Container(
  66. padding: EdgeInsets.only(top: 4),
  67. alignment: Alignment.center,
  68. child: Text(conversation.updateAt,
  69. textScaleFactor: 1.0,
  70. style: TextStyle(fontSize: 11, color: const Color(0xFFC6C6C6))),
  71. )
  72. ];
  73. if (conversation.unreadMsgCount > 0) {
  74. var countStr = conversation.unreadMsgCount.toString();
  75. if (conversation.unreadMsgCount > 99) {
  76. countStr = '99+';
  77. }
  78. // 未读消息角标
  79. Widget unreadMsgCountText = Container(
  80. width: Constants.UnReadMsgNotifyDotSize,
  81. height: Constants.UnReadMsgNotifyDotSize,
  82. alignment: Alignment.center,
  83. decoration: BoxDecoration(
  84. borderRadius:
  85. BorderRadius.circular(Constants.UnReadMsgNotifyDotSize / 2.0),
  86. color: Color(0xFFFF5454),
  87. ),
  88. child: Text(countStr,
  89. textScaleFactor: 1.0, style: AppStyles.UnreadMsgCountDotStyle),
  90. );
  91. _rightArea.add(Expanded(
  92. child: Align(
  93. alignment: Alignment.bottomCenter,
  94. child: unreadMsgCountText,
  95. )));
  96. }
  97. return InkWell(
  98. child: Container(
  99. padding: const EdgeInsets.all(10.0),
  100. decoration: BoxDecoration(
  101. color: Color(AppColors.ConversationItemBgColor),
  102. ),
  103. child: Row(
  104. crossAxisAlignment: CrossAxisAlignment.center,
  105. children: <Widget>[
  106. avatar,
  107. Container(width: 17.0),
  108. Expanded(
  109. child: Column(
  110. crossAxisAlignment: CrossAxisAlignment.start,
  111. children: <Widget>[
  112. Text(conversation.title,
  113. textScaleFactor: 1.0,
  114. style: TextStyle(
  115. color: Colors.black,
  116. )),
  117. SizedBox(
  118. height: 5,
  119. ),
  120. Text(conversation.desc,
  121. textScaleFactor: 1.0,
  122. style: TextStyle(
  123. fontSize: 12, color: const Color(0xFF9B9B9B)))
  124. ],
  125. ),
  126. ),
  127. // Container(width: 10.0),
  128. SizedBox(
  129. height: Constants.ConversationAvatarSize,
  130. child: Column(
  131. crossAxisAlignment: CrossAxisAlignment.end,
  132. mainAxisAlignment: MainAxisAlignment.start,
  133. children: _rightArea,
  134. ),
  135. )
  136. ],
  137. ),
  138. ),
  139. onTap: () {
  140. callback();
  141. },
  142. );
  143. }
  144. }
  145. class ConversActionPage extends StatefulWidget {
  146. ConversActionPage({Key key}) : super(key: key);
  147. _ConversActionPageState createState() => _ConversActionPageState();
  148. }
  149. Map systemInfo = {
  150. 'applyList': null,
  151. 'applyCount': 0,
  152. 'evaluateList': null,
  153. 'evaluateCount': 0,
  154. 'parkList': null,
  155. 'parkCount': 0,
  156. 'castList': null,
  157. 'castCount': 0,
  158. 'walletList': null,
  159. 'walletCount': 0,
  160. };
  161. int msgNum = 0;
  162. bool isShowMsg() {
  163. return msgNum > 0;
  164. }
  165. getAllResNum(prefs) {
  166. getResNum(prefs, Constants.ApplyCount);
  167. getResNum(prefs, Constants.EvaluateCount);
  168. getResNum(prefs, Constants.ParkCount);
  169. getResNum(prefs, Constants.CastCount);
  170. getResNum(prefs, Constants.WalletCount);
  171. }
  172. getResNum(prefs, url) async {
  173. var count = prefs.getInt(url + UserData().basicInfo.userId.toString());
  174. systemInfo[url] = count == null ? systemInfo[url] : (systemInfo[url] - count);
  175. msgNum += systemInfo[url];
  176. }
  177. setResNum(url) async {
  178. var localKey = url + UserData().basicInfo.userId.toString();
  179. if (systemInfo[url] > 0) {
  180. SharedPreferences prefs = await SharedPreferences.getInstance();
  181. var count = prefs.getInt(localKey);
  182. prefs.setInt(
  183. localKey, count == null ? systemInfo[url] : (systemInfo[url] + count));
  184. msgNum -= systemInfo[url];
  185. systemInfo[url] = 0;
  186. }
  187. }
  188. class _ConversActionPageState extends State<ConversActionPage>
  189. with SingleTickerProviderStateMixin {
  190. TabController tabCtrl;
  191. void getSystemMsg(data) async {
  192. Map data = {
  193. "userId": UserData().basicInfo.userId,
  194. "type": UserData().basicInfo.sex
  195. };
  196. data['sign'] = TokenMgr().getSign(data);
  197. Response res = await HttpUtil().post('message/all/message', data: data);
  198. if (res == null) {
  199. return;
  200. }
  201. Map resData = res.data;
  202. if (resData['code'] == 0) {
  203. SharedPreferences prefs = await SharedPreferences.getInstance();
  204. systemInfo = resData['data'];
  205. msgNum = 0;
  206. getAllResNum(prefs);
  207. if (mounted) {
  208. setState(() {});
  209. }
  210. }
  211. }
  212. @override
  213. void initState() {
  214. super.initState();
  215. MessageMgr().on('update_system', getSystemMsg);
  216. getSystemMsg(null);
  217. tabCtrl = TabController(length: 2, vsync: this);
  218. }
  219. @override
  220. void dispose() {
  221. tabCtrl.dispose();
  222. MessageMgr().off('update_system', getSystemMsg);
  223. super.dispose();
  224. }
  225. @override
  226. Widget build(BuildContext context) {
  227. return Scaffold(
  228. backgroundColor: Colors.white,
  229. appBar: AppBar(
  230. //backgroundColor: Constants.LightGreyBackgroundColor,
  231. centerTitle: false,
  232. title: Text(
  233. I18n.of(context).message_center,
  234. textScaleFactor: 1.0,
  235. style: Constants.MainTitleStyle,
  236. ),
  237. actions: <Widget>[
  238. Container(
  239. child: IconButton(
  240. icon: CircleAvatar(
  241. backgroundColor: Constants.GreyBackgroundColor,
  242. radius: 13.75,
  243. child: Padding(
  244. padding: EdgeInsets.only(bottom: 1.5),
  245. child: Icon(
  246. IconData(0xe659,
  247. fontFamily: Constants.IconFontFamily),
  248. color: Constants.BlackTextColor,
  249. size: 21,
  250. ))),
  251. onPressed: () {
  252. CustomUI().goScanPage(context);
  253. },
  254. ),
  255. ),
  256. // InkWell(
  257. // onTap: () {
  258. // Navigator.of(context).push(
  259. // new MaterialPageRoute(
  260. // builder: (context) {
  261. // return MessagePushPage();
  262. // },
  263. // ),
  264. // );
  265. // },
  266. // child: Padding(
  267. // padding: EdgeInsets.only(right: 10),
  268. // child: CircleAvatar(
  269. // backgroundColor: Constants.GreyBackgroundColor,
  270. // radius: 13.75,
  271. // child: Icon(
  272. // Icons.settings,
  273. // color: Constants.BlackTextColor,
  274. // size: 22,
  275. // )),
  276. // )),
  277. ],
  278. elevation: 0,
  279. bottom: PreferredSize(
  280. preferredSize: Size.fromHeight(28),
  281. child: Container(
  282. padding: EdgeInsets.only(left: 2),
  283. decoration: BoxDecoration(
  284. //color: Constants.LightGreyBackgroundColor,
  285. border:
  286. Border(bottom: BorderSide(color: Color(0xffeaeaea)))),
  287. alignment: Alignment.centerLeft,
  288. child: TabBar(
  289. isScrollable: true,
  290. indicatorPadding: EdgeInsets.only(left: 9, right: 9),
  291. tabs: <Widget>[
  292. UnreadDot(
  293. child: Container(
  294. margin: EdgeInsets.only(right: 4),
  295. child: Text(I18n.of(context).text_chat,
  296. textScaleFactor: 1.0),
  297. ),
  298. type: 1),
  299. UnreadDot(
  300. child: Container(
  301. margin: EdgeInsets.only(right: 4),
  302. child: Text(I18n.of(context).system_information,
  303. textScaleFactor: 1.0)),
  304. type: 2),
  305. ],
  306. controller: tabCtrl,
  307. ),
  308. )),
  309. ),
  310. body: SafeArea(
  311. child: TabBarView(
  312. children: <Widget>[
  313. LastChatPage(),
  314. ListView(
  315. children: <Widget>[
  316. SizedBox(height: 8.5),
  317. _ConversationItem(
  318. icon: 'assets/images/chat/icon1.png',
  319. bgColor: Constants.RadioGradient,
  320. conversation: Conversation(
  321. avatar: 'assets/images/ic_tx_news.png',
  322. title: I18n.of(context).radio_message,
  323. desc: RichTitle.normalTitle(
  324. systemInfo['castList'], context, InfoType.Radio),
  325. updateAt: systemInfo['castList'] == null
  326. ? ""
  327. : WebData().getLoginTime(
  328. context, systemInfo['castList']['CreateTime']),
  329. unreadMsgCount: systemInfo['castCount'],
  330. ),
  331. callback: () {
  332. setResNum(Constants.CastCount);
  333. Navigator.of(context).push(
  334. new MaterialPageRoute(
  335. builder: (context) {
  336. return InfoListPage(
  337. title: I18n.of(context).radio_message,
  338. type: InfoType.Radio,
  339. );
  340. },
  341. ),
  342. );
  343. },
  344. ),
  345. _ConversationItem(
  346. icon: 'assets/images/chat/icon4.png',
  347. bgColor: Constants.MoneyGradient,
  348. conversation: Conversation(
  349. avatar: 'assets/images/ic_tx_news.png',
  350. title: I18n.of(context).wallet_reminder,
  351. desc: RichTitle.normalTitle(
  352. systemInfo['walletList'], context, InfoType.Money),
  353. updateAt: systemInfo['walletList'] == null
  354. ? ""
  355. : WebData().getLoginTime(
  356. context, systemInfo['walletList']['CreateTime']),
  357. unreadMsgCount: systemInfo['walletCount'],
  358. ),
  359. callback: () {
  360. setResNum(Constants.WalletCount);
  361. Navigator.of(context).push(
  362. new MaterialPageRoute(
  363. builder: (context) {
  364. return InfoListPage(
  365. title: I18n.of(context).wallet_reminder,
  366. type: InfoType.Money,
  367. );
  368. },
  369. ),
  370. );
  371. },
  372. ),
  373. _ConversationItem(
  374. icon: 'assets/images/chat/icon3.png',
  375. iconSize: 27,
  376. bgColor: Constants.ApplyGradient,
  377. conversation: Conversation(
  378. avatar: 'assets/images/ic_tx_news.png',
  379. title: I18n.of(context).application_notice,
  380. desc: RichTitle.normalTitle(
  381. systemInfo['applyList'], context, InfoType.Apply),
  382. updateAt: systemInfo['applyList'] == null
  383. ? ""
  384. : WebData().getLoginTime(
  385. context, systemInfo['applyList']['CreatTime']),
  386. unreadMsgCount: systemInfo['applyCount'],
  387. ),
  388. callback: () {
  389. setResNum(Constants.ApplyCount);
  390. Navigator.of(context).push(
  391. new MaterialPageRoute(
  392. builder: (context) {
  393. return InfoListPage(
  394. title: I18n.of(context).application_notice,
  395. type: InfoType.Apply,
  396. );
  397. },
  398. ),
  399. );
  400. },
  401. ),
  402. _ConversationItem(
  403. icon: 'assets/images/chat/icon6.png',
  404. bgColor: Constants.EvaGradient,
  405. conversation: Conversation(
  406. avatar: 'assets/images/ic_tx_news.png',
  407. title: I18n.of(context).evaluation_notice,
  408. desc: RichTitle.normalTitle(systemInfo['evaluateList'],
  409. context, InfoType.Evaluation),
  410. updateAt: systemInfo['evaluateList'] == null
  411. ? ''
  412. : WebData().getLoginTime(
  413. context, systemInfo['evaluateList']['CreateTime']),
  414. unreadMsgCount: systemInfo['evaluateCount'],
  415. ),
  416. callback: () {
  417. setResNum(Constants.EvaluateCount);
  418. Navigator.of(context).push(
  419. new MaterialPageRoute(
  420. builder: (context) {
  421. return InfoListPage(
  422. title: I18n.of(context).evaluation_notice,
  423. type: 2,
  424. );
  425. },
  426. ),
  427. );
  428. },
  429. ),
  430. _ConversationItem(
  431. icon: 'assets/images/chat/icon5.png',
  432. bgColor: Constants.ParkGradient,
  433. conversation: Conversation(
  434. avatar: 'assets/images/ic_tx_news.png',
  435. title: I18n.of(context).appName,
  436. desc: RichTitle.normalTitle(
  437. systemInfo['parkList'], context, InfoType.System),
  438. updateAt: systemInfo['parkList'] == null
  439. ? ""
  440. : WebData().getLoginTime(
  441. context, systemInfo['parkList']['CreateTime']),
  442. unreadMsgCount: systemInfo['parkCount'],
  443. ),
  444. callback: () {
  445. setResNum(Constants.ParkCount);
  446. Navigator.of(context).push(
  447. new MaterialPageRoute(
  448. builder: (context) {
  449. return InfoListPage(
  450. title: I18n.of(context).appName,
  451. type: InfoType.System,
  452. );
  453. },
  454. ),
  455. );
  456. },
  457. )
  458. ],
  459. )
  460. ],
  461. controller: tabCtrl,
  462. )));
  463. }
  464. }