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.
 
 
 
 
 
 

164 lines
4.7 KiB

  1. import 'package:chat/data/group_data_mgr.dart';
  2. import 'package:chat/home/global_search.dart';
  3. import 'package:chat/models/group_info_model.dart';
  4. import 'package:chat/utils/MessageMgr.dart';
  5. import 'package:chat/utils/screen.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:chat/data/constants.dart';
  8. import 'package:chat/generated/i18n.dart';
  9. import 'package:chat/utils/CustomUI.dart';
  10. import 'create_group_view.dart';
  11. import 'group_item_widget.dart';
  12. class GroupChatListPage extends StatefulWidget {
  13. @override
  14. _GroupChatListPageState createState() => _GroupChatListPageState();
  15. }
  16. class _GroupChatListPageState extends State<GroupChatListPage> {
  17. ScrollController _scrollController = ScrollController();
  18. List<GroupInfoModel> searchList = [];
  19. @override
  20. void initState() {
  21. super.initState();
  22. print('GroupChatListPage initState');
  23. MessageMgr().on('Quit Group', quitGroup);
  24. MessageMgr().on('Update Group List', updateGroupLastMsg);
  25. }
  26. updateGroupLastMsg(args) async {
  27. await GroupInfoMgr().sortGroupList();
  28. if (mounted) {
  29. setState(() {});
  30. }
  31. }
  32. @override
  33. void dispose() {
  34. _scrollController.dispose();
  35. MessageMgr().off('Update Group List', updateGroupLastMsg);
  36. MessageMgr().off('Quit Group', quitGroup);
  37. super.dispose();
  38. }
  39. quitGroup(args) {
  40. if (mounted) {
  41. setState(() {
  42. print('更新群列表');
  43. });
  44. }
  45. }
  46. Widget _buildCreateButton() {
  47. List<GroupInfoModel> groupList = GroupInfoMgr().groupInfoList;
  48. Widget _avatarIcon = ClipRRect(
  49. borderRadius: BorderRadius.circular(GroupRadius),
  50. child: Container(
  51. color: const Color(0xFFF2F2F2),
  52. height: AvatarSize,
  53. width: AvatarSize,
  54. child: Icon(
  55. IconData(0xe66f, fontFamily: Constants.IconFontFamily),
  56. color: Constants.BlueTextColor,
  57. size: 35,
  58. ),
  59. ));
  60. Widget _button = InkWell(
  61. onTap: () {
  62. Navigator.of(context).push(
  63. new MaterialPageRoute(
  64. builder: (context) {
  65. return CreateGroupPage(
  66. GroupOperatingPageType.CreateGroup, [], null);
  67. },
  68. ),
  69. );
  70. },
  71. child: Container(
  72. height: ItemHeight,
  73. margin: EdgeInsets.only(top: 6.5, bottom: 16),
  74. decoration: BoxDecoration(color: Colors.white),
  75. child: Row(
  76. children: <Widget>[
  77. SizedBox(width: LeftPadding),
  78. _avatarIcon,
  79. SizedBox(width: 14.0),
  80. Text(
  81. I18n.of(context).create_group_chat,
  82. style: TextStyle(fontSize: 15.5),
  83. ),
  84. ],
  85. ),
  86. ));
  87. Widget tips = Container(
  88. alignment: Alignment.centerLeft,
  89. width: Screen.width,
  90. height: 33.5,
  91. padding: EdgeInsets.only(left: LeftPadding),
  92. decoration: BoxDecoration(
  93. color: Colors.white,
  94. border: Border(bottom: Constants.GreyBorderSide)),
  95. child: Text(I18n.of(context).group_chat + '(${groupList.length})'),
  96. );
  97. return Column(
  98. children: <Widget>[
  99. _button,
  100. tips,
  101. ],
  102. );
  103. }
  104. @override
  105. Widget build(BuildContext context) {
  106. List<GroupInfoModel> groupList = GroupInfoMgr().groupInfoList;
  107. print('build group chat Page 群数量${groupList.length}');
  108. final List<Widget> _body = [];
  109. _body.add(
  110. ListView.builder(
  111. controller: _scrollController,
  112. itemBuilder: (BuildContext context, int index) {
  113. if (index == 0) {
  114. return _buildCreateButton();
  115. } else {
  116. var info = groupList[index - 1];
  117. return GroupItem(ValueKey(info), groupInfoModel: info);
  118. }
  119. },
  120. itemCount: groupList.length + 1,
  121. ),
  122. );
  123. return Scaffold(
  124. resizeToAvoidBottomPadding: false,
  125. appBar: AppBar(
  126. backgroundColor: AppColors.NewAppbarBgColor,
  127. title: Text(I18n.of(context).group_chat,
  128. textScaleFactor: 1.0, style: Constants.MainTitleStyle),
  129. centerTitle: false,
  130. elevation: 1,
  131. bottom: CustomUI.buildSearchButton(context, () {
  132. Navigator.of(context).push(
  133. new MaterialPageRoute(
  134. builder: (context) {
  135. return GlobalSearchPage(
  136. type: GlobalSearchPageType.SearchGroup,
  137. );
  138. },
  139. ),
  140. );
  141. })),
  142. body: Stack(
  143. children: _body,
  144. ));
  145. }
  146. }