Hibok
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

682 строки
23 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. textScaleFactor: 1.0,
  340. style:
  341. TextStyle(fontSize: 12, color: Color(0xff777777)),
  342. ),
  343. ),
  344. Divider(
  345. color: Color(0xffE5E5E5),
  346. ),
  347. InkWell(
  348. onTap: function,
  349. child: Container(
  350. height: 60,
  351. alignment: Alignment.center,
  352. child: Text(I18n.of(context).determine,
  353. textScaleFactor: 1.0,
  354. style: TextStyle(
  355. fontSize: 18,
  356. color: Constants.ConfrimButtonColor)),
  357. ),
  358. ),
  359. Container(
  360. color: Color(0xffF2F2F2),
  361. height: 4,
  362. ),
  363. InkWell(
  364. onTap: () {
  365. Navigator.of(context).pop();
  366. },
  367. child: Container(
  368. height: 60,
  369. alignment: Alignment.center,
  370. child: Text(I18n.of(context).cancel,
  371. textScaleFactor: 1.0,
  372. style: TextStyle(
  373. fontSize: 18, color: Color(0xff4B4B4B))),
  374. ),
  375. )
  376. ],
  377. ),
  378. );
  379. },
  380. );
  381. },
  382. child: Container(
  383. height: 40,
  384. margin: EdgeInsets.symmetric(horizontal: 40),
  385. alignment: Alignment.center,
  386. child: Text(
  387. title,
  388. textScaleFactor: 1.0,
  389. style:
  390. TextStyle(color: Constants.ConfrimButtonColor, fontSize: 15),
  391. ),
  392. ),
  393. ));
  394. }
  395. ///群公告
  396. Widget groupAnnounce() {
  397. return InkWell(
  398. onTap: () {
  399. if (widget.groupInfoModel.describe == '' && !isHost) {
  400. showToast(I18n.of(context).only_host);
  401. return;
  402. }
  403. Navigator.of(context).push(
  404. new MaterialPageRoute(
  405. builder: (context) {
  406. return GroupAnnouncementPage(
  407. groupInfoModel: widget.groupInfoModel,
  408. );
  409. },
  410. ),
  411. );
  412. },
  413. child: Container(
  414. color: Colors.white,
  415. child: Column(
  416. children: <Widget>[
  417. Container(
  418. padding: EdgeInsets.symmetric(
  419. horizontal: Separate_Size, vertical: 12),
  420. color: Colors.white,
  421. child: Row(
  422. children: <Widget>[
  423. Column(
  424. crossAxisAlignment: CrossAxisAlignment.start,
  425. children: <Widget>[
  426. Padding(
  427. padding: EdgeInsets.only(top: 0, left: 4),
  428. child: Text(
  429. I18n.of(context).group_announcement,
  430. textScaleFactor: 1.0,
  431. style: TextStyle(
  432. color: Colors.black, fontSize: 14),
  433. ),
  434. ),
  435. widget.groupInfoModel.describe == null ||
  436. widget.groupInfoModel.describe == ""
  437. ? Container()
  438. : Container(
  439. width: Screen.width - 55,
  440. padding: EdgeInsets.only(top: 3, left: 4),
  441. child: Text(
  442. widget.groupInfoModel.describe,
  443. textScaleFactor: 1.0,
  444. maxLines: 1,
  445. overflow: TextOverflow.ellipsis,
  446. style: TextStyle(
  447. color: Color(0xff818181),
  448. fontSize: 11),
  449. ),
  450. ),
  451. ]),
  452. Expanded(
  453. child: SizedBox(),
  454. ),
  455. Padding(
  456. padding: EdgeInsets.only(bottom: 0),
  457. child: Icon(
  458. IconData(0xe63c, fontFamily: 'iconfont'),
  459. size: 20.0,
  460. color: Color(AppColors.TabIconNormal),
  461. ))
  462. ],
  463. )),
  464. Container(
  465. margin: EdgeInsets.symmetric(horizontal: 15),
  466. decoration: BoxDecoration(
  467. border: Border(
  468. bottom: Constants.GreyBorderSide,
  469. ),
  470. ),
  471. )
  472. ],
  473. )));
  474. }
  475. ///群成员显示
  476. Widget buildMember(
  477. Function addMember, Function deleteMember, Function seeMoreMember) {
  478. // List<GroupMemberModel> members = widget.groupInfoModel.getMembersInGroup();
  479. List<GroupMemberModel> members = [];
  480. for (int k = 0; k < widget.groupInfoModel.members.length; k++) {
  481. //只加入存在群的
  482. GroupMemberModel mo = widget.groupInfoModel.members[k];
  483. if (mo.inGroup == 1) {
  484. members.add(mo);
  485. }
  486. }
  487. members.sort((GroupMemberModel left, GroupMemberModel right) =>
  488. right.identity.compareTo(left.identity));
  489. print('群成员数量- ${members.length}');
  490. int length = members.length;
  491. int dex = isHost ? 2 : 1;
  492. int shouldShow = length > (10 - dex) ? 10 - dex : length;
  493. double size = Screen.width / 5;
  494. List<Widget> list = [];
  495. for (int index = 0; index < shouldShow; index++) {
  496. var member = members[index];
  497. var refName = Provider.of<RefNameProvider>(context)
  498. .getGroupRefName(widget.groupInfoModel.sessionId, member.memberId);
  499. list.add(GestureDetector(
  500. child: Container(
  501. child: Column(
  502. children: <Widget>[
  503. ClipRRect(
  504. borderRadius: BorderRadius.all(Radius.circular(8.0)),
  505. child: CachedNetworkImage(
  506. imageUrl: member.avtar,
  507. placeholder: (context, url) => Image.asset(
  508. Constants.DefaultHeadImgUrl,
  509. width: size - 30,
  510. height: size - 30,
  511. ),
  512. width: size - 30,
  513. height: size - 30,
  514. )),
  515. SizedBox(
  516. height: 5,
  517. ),
  518. Container(
  519. width: size - 30,
  520. alignment: Alignment.center,
  521. child: Text(
  522. refName,
  523. textScaleFactor: 1.0,
  524. style: TextStyle(fontSize: 11, color: Color(0xff818181)),
  525. maxLines: 1,
  526. overflow: TextOverflow.ellipsis,
  527. ),
  528. )
  529. ],
  530. ),
  531. width: size,
  532. height: size,
  533. ),
  534. behavior: HitTestBehavior.translucent,
  535. onTap: () {
  536. if (members[index].memberId != UserData().basicInfo.userId) {
  537. AppNavigator.pushProfileInfoPage(context, members[index].memberId,
  538. fromWhere: 2, addMode: 1);
  539. }
  540. },
  541. ));
  542. }
  543. list.add(GestureDetector(
  544. onTap: addMember,
  545. child: Container(
  546. width: size,
  547. height: size,
  548. child: Column(
  549. children: <Widget>[
  550. Container(
  551. alignment: Alignment.center,
  552. width: size - 30,
  553. height: size - 30,
  554. child: Text(
  555. '+',
  556. textScaleFactor: 1.0,
  557. style: TextStyle(fontSize: 30, color: Color(0xffB1B1B1)),
  558. ),
  559. decoration: BoxDecoration(
  560. border: Border.all(color: Color(0xffC3C3C3), width: 1.0),
  561. borderRadius: BorderRadius.all(Radius.circular(6))),
  562. )
  563. ],
  564. ),
  565. ),
  566. ));
  567. if (isHost) {
  568. list.add(Container(
  569. width: size,
  570. height: size,
  571. child: Column(
  572. children: <Widget>[
  573. GestureDetector(
  574. onTap: deleteMember,
  575. child: Container(
  576. alignment: Alignment.center,
  577. width: size - 30,
  578. height: size - 30,
  579. child: Container(
  580. color: Color(0xffB1B1B1),
  581. width: 20,
  582. height: 2.6,
  583. ),
  584. decoration: BoxDecoration(
  585. border: Border.all(color: Color(0xffC3C3C3), width: 1.0),
  586. borderRadius: BorderRadius.all(Radius.circular(6))),
  587. ),
  588. )
  589. ],
  590. ),
  591. ));
  592. }
  593. return Container(
  594. color: Color(0xffFAFAFA),
  595. child: Column(
  596. crossAxisAlignment: CrossAxisAlignment.start,
  597. children: <Widget>[
  598. SizedBox(
  599. height: 5,
  600. ),
  601. Wrap(
  602. children: list,
  603. crossAxisAlignment: WrapCrossAlignment.start,
  604. alignment: WrapAlignment.start,
  605. ),
  606. length > (10 - dex)
  607. ? GestureDetector(
  608. onTap: seeMoreMember,
  609. child: Container(
  610. height: 35,
  611. child: Row(
  612. mainAxisAlignment: MainAxisAlignment.center,
  613. children: <Widget>[
  614. Text(
  615. I18n.of(context).show_more_member,
  616. textScaleFactor: 1.0,
  617. style: TextStyle(color: Color(0xff818181)),
  618. ),
  619. Padding(
  620. padding: EdgeInsets.only(bottom: 1.5),
  621. child: Icon(
  622. IconData(0xe63c, fontFamily: 'iconfont'),
  623. size: 20.0,
  624. color: Color(AppColors.TabIconNormal),
  625. ))
  626. ],
  627. ),
  628. ),
  629. )
  630. : Container(),
  631. ],
  632. ),
  633. );
  634. }
  635. }