Hibok
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

672 рядки
22 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/UserData.dart';
  3. import 'package:chat/data/chat_data_mgr.dart';
  4. import 'package:chat/data/group_data_mgr.dart';
  5. import 'package:chat/home/add_friend.dart';
  6. import 'package:chat/home/group_announcement.dart';
  7. import 'package:chat/home/group_manage_page.dart';
  8. import 'package:chat/models/group_info_model.dart';
  9. import 'package:chat/models/ref_name_provider.dart';
  10. import 'package:chat/utils/MessageMgr.dart';
  11. import 'package:chat/utils/group_member_model.dart';
  12. import 'package:chat/utils/msgHandler.dart';
  13. import 'package:chat/utils/screen.dart';
  14. import 'package:flutter/cupertino.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:oktoast/oktoast.dart';
  17. import 'package:provider/provider.dart';
  18. import '../data/constants.dart';
  19. import '../generated/i18n.dart';
  20. import '../utils/CustomUI.dart';
  21. import '../utils/FullWithButton.dart';
  22. import '../utils/app_navigator.dart';
  23. import 'create_group_view.dart';
  24. class GroupSetting extends StatefulWidget {
  25. final GroupInfoModel groupInfoModel;
  26. GroupSetting({Key key, this.groupInfoModel}) : super(key: key);
  27. @override
  28. State<StatefulWidget> createState() {
  29. return GroupSettingState();
  30. }
  31. }
  32. class GroupSettingState extends State<GroupSetting> {
  33. static const Separate_Size = 15.0;
  34. bool notice = true; //消息提示
  35. bool stickyChat = false; //置顶聊天
  36. bool showGroupFriendNickname = true; //显示群成员昵称
  37. bool isHost;
  38. ///是否是群主
  39. @override
  40. void initState() {
  41. super.initState();
  42. stickyChat = widget.groupInfoModel.topTag > 0;
  43. MessageMgr().on('Update Group Info', updateGroupInfo);
  44. notice = widget.groupInfoModel.messageFree == 1;
  45. showGroupFriendNickname = widget.groupInfoModel.isShowName > 0;
  46. print(
  47. ' widget.groupInfoModel.hosterId : ${widget.groupInfoModel.hosterId}');
  48. }
  49. @override
  50. void dispose() {
  51. MessageMgr().off('Update Group Info', updateGroupInfo);
  52. super.dispose();
  53. }
  54. updateGroupInfo(args) {
  55. print('群设置 - 更新群信息');
  56. if (mounted) {
  57. setState(() {});
  58. }
  59. }
  60. quitGroup() {
  61. print('退出所有页面');
  62. GroupInfoMgr().deleteGroup(widget.groupInfoModel.sessionId);
  63. MessageMgr().emit('Quit Group', widget.groupInfoModel.sessionId);
  64. Navigator.of(context).popUntil(ModalRoute.withName('/main'));
  65. }
  66. //清空聊天记录
  67. clearRecord() {
  68. //清楚最后一条数据
  69. widget.groupInfoModel.lastMsg = null;
  70. //清空聊天数据
  71. ChatDataMgr().deleteMsg(widget.groupInfoModel.sessionId, true);
  72. }
  73. @override
  74. Widget build(BuildContext context) {
  75. isHost = widget.groupInfoModel.hosterId == UserData().basicInfo.userId;
  76. print(widget.groupInfoModel.myName);
  77. Widget appBar = AppBar(
  78. backgroundColor: AppColors.NewAppbarBgColor,
  79. title: new Text(
  80. I18n.of(context).chat_news +
  81. '(${widget.groupInfoModel.getMembersInGroup().length})',
  82. textScaleFactor: 1.0,
  83. style: TextStyle(color: AppColors.NewAppbarTextColor),
  84. ),
  85. leading: CustomUI.buildCustomLeading(context),
  86. centerTitle: true,
  87. );
  88. var groupName =
  89. (widget.groupInfoModel.name == '' || widget.groupInfoModel.name == null)
  90. ? I18n.of(context).undefine_name
  91. : widget.groupInfoModel.name;
  92. return Scaffold(
  93. appBar: appBar,
  94. body: SafeArea(
  95. child: ListView(
  96. children: <Widget>[
  97. SizedBox(
  98. height: 12,
  99. ),
  100. ///群成员
  101. buildMember(
  102. () {
  103. ///添加成员
  104. Navigator.of(context).push(
  105. new MaterialPageRoute(
  106. builder: (context) {
  107. return CreateGroupPage(
  108. GroupOperatingPageType.AddMember,
  109. widget.groupInfoModel.getMembersInGroup(),
  110. widget.groupInfoModel.sessionId);
  111. },
  112. ),
  113. );
  114. },
  115. () {
  116. ///删除成员
  117. Navigator.of(context).push(
  118. new MaterialPageRoute(
  119. builder: (context) {
  120. return CreateGroupPage(
  121. GroupOperatingPageType.DeleteMember,
  122. widget.groupInfoModel.getMembersInGroup(),
  123. widget.groupInfoModel.sessionId);
  124. },
  125. ),
  126. );
  127. },
  128. () {
  129. /// 查看更多成员
  130. AppNavigator.pushGroupAllMember(context, widget.groupInfoModel);
  131. },
  132. ),
  133. SizedBox(
  134. height: 12,
  135. ),
  136. ///群聊名称
  137. _buildSetting(I18n.of(context).group_chat_name, groupName, () {
  138. if (widget.groupInfoModel.canAlterGroupName()) {
  139. Navigator.of(context).push(
  140. new MaterialPageRoute(
  141. builder: (context) {
  142. return AddFriendPage(
  143. userId: widget.groupInfoModel.sessionId,
  144. pageType: SendMessagePageType.ChangeGroupName,
  145. originalName: groupName,
  146. );
  147. },
  148. ),
  149. );
  150. } else {
  151. showToast('权限不足');
  152. }
  153. }),
  154. ///群二维码
  155. UserData().groupQRCode == 0
  156. ? Container()
  157. : _buildSetting(I18n.of(context).group_qr, '', () {
  158. AppNavigator.pushGroupQrPage(
  159. context, widget.groupInfoModel);
  160. },
  161. extendWidget: Icon(
  162. IconData(0xe658, fontFamily: 'iconfont'),
  163. size: 20.0,
  164. color: Color(AppColors.TabIconNormal),
  165. )),
  166. ///群公告
  167. groupAnnounce(),
  168. ///群管理
  169. widget.groupInfoModel.hosterId == UserData().basicInfo.userId
  170. ? _buildSetting(I18n.of(context).group_setting, '', () {
  171. Navigator.of(context).push(
  172. new MaterialPageRoute(
  173. builder: (context) {
  174. return GroupManagePage(
  175. groupInfoModel: widget.groupInfoModel,
  176. );
  177. },
  178. ),
  179. );
  180. }, showDivider: false)
  181. : Container(),
  182. SizedBox(
  183. height: 11,
  184. ),
  185. ///消息免打扰
  186. _buildSettingWithSwitch(notice, I18n.of(context).close_news_notice,
  187. (bool val) {
  188. setState(() {
  189. notice = val;
  190. MsgHandler.updateMemberMsgFreeReq(
  191. widget.groupInfoModel.sessionId, notice);
  192. });
  193. }),
  194. Container(
  195. height: 0.5,
  196. color: Colors.white,
  197. child: Container(
  198. color: Color(0xffE5E5E5),
  199. ),
  200. padding: EdgeInsets.symmetric(horizontal: 20),
  201. ),
  202. ///置顶聊天
  203. _buildSettingWithSwitch(stickyChat, I18n.of(context).set_chat_top,
  204. (bool val) {
  205. setState(() {
  206. stickyChat = val;
  207. widget.groupInfoModel.updateTopTag(stickyChat);
  208. MessageMgr().emit('Update Group List');
  209. });
  210. }),
  211. SizedBox(
  212. height: 11,
  213. ),
  214. ///我在本群的昵称
  215. _buildSetting(
  216. I18n.of(context).my_group_nickname,
  217. widget.groupInfoModel.myName == null
  218. ? UserData().basicInfo.nickName
  219. : widget.groupInfoModel.myName, () {
  220. Navigator.of(context).push(
  221. new MaterialPageRoute(
  222. builder: (context) {
  223. return AddFriendPage(
  224. userId: widget.groupInfoModel.sessionId,
  225. pageType: SendMessagePageType.ChangeGroupNickName,
  226. originalName: widget.groupInfoModel.myName,
  227. );
  228. },
  229. ),
  230. );
  231. }),
  232. ///显示群成员昵称
  233. _buildSettingWithSwitch(showGroupFriendNickname,
  234. I18n.of(context).show_group_member_name, (bool val) {
  235. setState(() {
  236. showGroupFriendNickname = val;
  237. widget.groupInfoModel.updateShowNameSwitch(val);
  238. });
  239. }),
  240. SizedBox(
  241. height: 11,
  242. ),
  243. ///清除聊天记录
  244. _buildSettingWithConfirm(I18n.of(context).group_clean_chat_record,
  245. I18n.of(context).group_clean_chat_record, () {
  246. clearRecord();
  247. Navigator.of(context).pop();
  248. }),
  249. Padding(
  250. padding: EdgeInsets.symmetric(horizontal: Separate_Size),
  251. child: Divider(
  252. color: Color(0xffE5E5E5),
  253. height: 0.6,
  254. ),
  255. ),
  256. ///退出并删除按钮
  257. _buildSettingWithConfirm(I18n.of(context).quit_and_delete,
  258. I18n.of(context).quit_group_tips, () {
  259. print('退出群聊');
  260. quitGroup();
  261. MsgHandler.quitGroup(widget.groupInfoModel.sessionId);
  262. }),
  263. ],
  264. ),
  265. ),
  266. );
  267. }
  268. Widget _buildSetting(String title, String desc, Function func,
  269. {showRightIcon = true, showDivider = true, extendWidget}) {
  270. //版本
  271. return Container(
  272. padding: EdgeInsets.symmetric(horizontal: 10),
  273. child: FullWidthButton(
  274. showRightIcon: showRightIcon,
  275. title: title,
  276. description: desc,
  277. extendWidget: extendWidget,
  278. showDivider: showDivider,
  279. onPressed: func,
  280. ),
  281. decoration: BoxDecoration(
  282. color: Colors.white,
  283. ),
  284. );
  285. }
  286. Widget _buildSettingWithSwitch(
  287. bool switchValue, String title, Function onchang) {
  288. Widget left = new Text(
  289. title,
  290. textScaleFactor: 1.0,
  291. style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal),
  292. );
  293. Widget right = new Expanded(
  294. child: new Container(
  295. alignment: Alignment.centerRight,
  296. padding: EdgeInsets.only(right: 8),
  297. child: new Switch(
  298. value: switchValue,
  299. activeTrackColor: Constants.ConfrimButtonColor.withOpacity(0.3),
  300. onChanged: onchang,
  301. )));
  302. return new Container(
  303. decoration: BoxDecoration(
  304. color: Colors.white,
  305. ),
  306. padding: EdgeInsets.only(left: 20),
  307. height: 53,
  308. child: new Row(
  309. children: <Widget>[left, right],
  310. ),
  311. );
  312. }
  313. Widget _buildSettingWithConfirm(
  314. String title, String dialogTips, Function function) {
  315. return Container(
  316. color: Colors.white,
  317. padding: EdgeInsets.only(top: 11, bottom: 11),
  318. child: InkWell(
  319. onTap: () {
  320. showModalBottomSheet(
  321. context: context,
  322. backgroundColor: Colors.transparent,
  323. builder: (BuildContext context) {
  324. return Container(
  325. decoration: BoxDecoration(
  326. color: Colors.white,
  327. borderRadius: BorderRadius.only(
  328. topLeft: Radius.circular(13),
  329. topRight: Radius.circular(13))),
  330. height: 225,
  331. child: Column(
  332. crossAxisAlignment: CrossAxisAlignment.center,
  333. mainAxisAlignment: MainAxisAlignment.center,
  334. children: <Widget>[
  335. Padding(
  336. padding: EdgeInsets.fromLTRB(15, 15, 15, 13),
  337. child: Text(
  338. dialogTips,
  339. style:
  340. TextStyle(fontSize: 12, color: Color(0xff777777)),
  341. ),
  342. ),
  343. Divider(
  344. color: Color(0xffE5E5E5),
  345. ),
  346. InkWell(
  347. onTap: function,
  348. child: Container(
  349. height: 60,
  350. alignment: Alignment.center,
  351. child: Text(I18n.of(context).determine,
  352. style: TextStyle(
  353. fontSize: 18,
  354. color: Constants.ConfrimButtonColor)),
  355. ),
  356. ),
  357. Container(
  358. color: Color(0xffF2F2F2),
  359. height: 4,
  360. ),
  361. InkWell(
  362. onTap: () {
  363. Navigator.of(context).pop();
  364. },
  365. child: Container(
  366. height: 60,
  367. alignment: Alignment.center,
  368. child: Text(I18n.of(context).cancel,
  369. style: TextStyle(
  370. fontSize: 18, color: Color(0xff4B4B4B))),
  371. ),
  372. )
  373. ],
  374. ),
  375. );
  376. },
  377. );
  378. },
  379. child: Container(
  380. height: 40,
  381. margin: EdgeInsets.symmetric(horizontal: 40),
  382. alignment: Alignment.center,
  383. child: Text(
  384. title,
  385. style:
  386. TextStyle(color: Constants.ConfrimButtonColor, fontSize: 15),
  387. ),
  388. ),
  389. ));
  390. }
  391. ///群公告
  392. Widget groupAnnounce() {
  393. return InkWell(
  394. onTap: () {
  395. if (widget.groupInfoModel.describe == '' && !isHost) {
  396. showToast(I18n.of(context).only_host);
  397. return;
  398. }
  399. Navigator.of(context).push(
  400. new MaterialPageRoute(
  401. builder: (context) {
  402. return GroupAnnouncementPage(
  403. groupInfoModel: widget.groupInfoModel,
  404. );
  405. },
  406. ),
  407. );
  408. },
  409. child: Container(
  410. color: Colors.white,
  411. child: Column(
  412. children: <Widget>[
  413. Container(
  414. padding: EdgeInsets.symmetric(
  415. horizontal: Separate_Size, vertical: 12),
  416. color: Colors.white,
  417. child: Row(
  418. children: <Widget>[
  419. Column(
  420. crossAxisAlignment: CrossAxisAlignment.start,
  421. children: <Widget>[
  422. Padding(
  423. padding: EdgeInsets.only(top: 0, left: 4),
  424. child: Text(
  425. I18n.of(context).group_announcement,
  426. style: TextStyle(
  427. color: Colors.black, fontSize: 14),
  428. ),
  429. ),
  430. widget.groupInfoModel.describe == null ||
  431. widget.groupInfoModel.describe == ""
  432. ? Container()
  433. : Container(
  434. width: Screen.width - 55,
  435. padding: EdgeInsets.only(top: 3, left: 4),
  436. child: Text(
  437. widget.groupInfoModel.describe,
  438. maxLines: 1,
  439. overflow: TextOverflow.ellipsis,
  440. style: TextStyle(
  441. color: Color(0xff818181),
  442. fontSize: 11),
  443. ),
  444. ),
  445. ]),
  446. Expanded(
  447. child: SizedBox(),
  448. ),
  449. Padding(
  450. padding: EdgeInsets.only(bottom: 0),
  451. child: Icon(
  452. IconData(0xe63c, fontFamily: 'iconfont'),
  453. size: 20.0,
  454. color: Color(AppColors.TabIconNormal),
  455. ))
  456. ],
  457. )),
  458. Container(
  459. margin: EdgeInsets.symmetric(horizontal: 15),
  460. decoration: BoxDecoration(
  461. border: Border(
  462. bottom: Constants.GreyBorderSide,
  463. ),
  464. ),
  465. )
  466. ],
  467. )));
  468. }
  469. ///群成员显示
  470. Widget buildMember(
  471. Function addMember, Function deleteMember, Function seeMoreMember) {
  472. // List<GroupMemberModel> members = widget.groupInfoModel.getMembersInGroup();
  473. List<GroupMemberModel> members = [];
  474. for (int k = 0; k < widget.groupInfoModel.members.length; k++) {
  475. //只加入存在群的
  476. GroupMemberModel mo = widget.groupInfoModel.members[k];
  477. if (mo.inGroup == 1) {
  478. members.add(mo);
  479. }
  480. }
  481. members.sort((GroupMemberModel left, GroupMemberModel right) =>
  482. right.identity.compareTo(left.identity));
  483. print('群成员数量- ${members.length}');
  484. int length = members.length;
  485. int dex = isHost ? 2 : 1;
  486. int shouldShow = length > (10 - dex) ? 10 - dex : length;
  487. double size = Screen.width / 5;
  488. List<Widget> list = [];
  489. for (int index = 0; index < shouldShow; index++) {
  490. var member = members[index];
  491. var refName = Provider.of<RefNameProvider>(context)
  492. .getGroupRefName(widget.groupInfoModel.sessionId, member.memberId);
  493. list.add(GestureDetector(
  494. child: Container(
  495. child: Column(
  496. children: <Widget>[
  497. ClipRRect(
  498. borderRadius: BorderRadius.all(Radius.circular(8.0)),
  499. child: CachedNetworkImage(
  500. imageUrl: member.avtar,
  501. placeholder: CustomUI.buildImgLoding,
  502. width: size - 30,
  503. height: size - 30,
  504. )),
  505. SizedBox(
  506. height: 5,
  507. ),
  508. SizedBox(
  509. width:size - 30,
  510. child: Text(
  511. refName,
  512. style: TextStyle(fontSize: 11, color: Color(0xff818181)),
  513. maxLines: 1,
  514. overflow: TextOverflow.ellipsis,
  515. ),
  516. )
  517. ],
  518. ),
  519. width: size,
  520. height: size,
  521. ),
  522. behavior: HitTestBehavior.translucent,
  523. onTap: () {
  524. if (members[index].memberId != UserData().basicInfo.userId) {
  525. AppNavigator.pushProfileInfoPage(context, members[index].memberId,
  526. fromWhere: 2,addMode: 1);
  527. }
  528. },
  529. ));
  530. }
  531. list.add(GestureDetector(
  532. onTap: addMember,
  533. child: Container(
  534. width: size,
  535. height: size,
  536. child: Column(
  537. children: <Widget>[
  538. Container(
  539. alignment: Alignment.center,
  540. width: size - 30,
  541. height: size - 30,
  542. child: Text(
  543. '+',
  544. textScaleFactor: 1.0,
  545. style: TextStyle(fontSize: 30, color: Color(0xffB1B1B1)),
  546. ),
  547. decoration: BoxDecoration(
  548. border: Border.all(color: Color(0xffC3C3C3), width: 1.0),
  549. borderRadius: BorderRadius.all(Radius.circular(6))),
  550. )
  551. ],
  552. ),
  553. ),
  554. ));
  555. if (isHost) {
  556. list.add(Container(
  557. width: size,
  558. height: size,
  559. child: Column(
  560. children: <Widget>[
  561. GestureDetector(
  562. onTap: deleteMember,
  563. child: Container(
  564. alignment: Alignment.center,
  565. width: size - 30,
  566. height: size - 30,
  567. child: Container(
  568. color: Color(0xffB1B1B1),
  569. width: 20,
  570. height: 2.6,
  571. ),
  572. decoration: BoxDecoration(
  573. border: Border.all(color: Color(0xffC3C3C3), width: 1.0),
  574. borderRadius: BorderRadius.all(Radius.circular(6))),
  575. ),
  576. )
  577. ],
  578. ),
  579. ));
  580. }
  581. return Container(
  582. color: Color(0xffFAFAFA),
  583. child: Column(
  584. crossAxisAlignment: CrossAxisAlignment.start,
  585. children: <Widget>[
  586. SizedBox(
  587. height: 5,
  588. ),
  589. Wrap(
  590. children: list,
  591. crossAxisAlignment: WrapCrossAlignment.start,
  592. alignment: WrapAlignment.start,
  593. ),
  594. length > (10 - dex)
  595. ? GestureDetector(
  596. onTap: seeMoreMember,
  597. child: Container(
  598. height: 35,
  599. child: Row(
  600. mainAxisAlignment: MainAxisAlignment.center,
  601. children: <Widget>[
  602. Text(
  603. I18n.of(context).show_more_member,
  604. textScaleFactor: 1.0,
  605. style: TextStyle(color: Color(0xff818181)),
  606. ),
  607. Padding(
  608. padding: EdgeInsets.only(bottom: 1.5),
  609. child: Icon(
  610. IconData(0xe63c, fontFamily: 'iconfont'),
  611. size: 20.0,
  612. color: Color(AppColors.TabIconNormal),
  613. ))
  614. ],
  615. ),
  616. ),
  617. )
  618. : Container(),
  619. ],
  620. ),
  621. );
  622. }
  623. }