Hibok
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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