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

165 рядки
4.8 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. textScaleFactor: 1.0,
  83. style: TextStyle(fontSize: 15.5),
  84. ),
  85. ],
  86. ),
  87. ));
  88. Widget tips = Container(
  89. alignment: Alignment.centerLeft,
  90. width: Screen.width,
  91. height: 33.5,
  92. padding: EdgeInsets.only(left: LeftPadding),
  93. decoration: BoxDecoration(
  94. color: Colors.white,
  95. border: Border(bottom: Constants.GreyBorderSide)),
  96. child: Text(I18n.of(context).group_chat + '(${groupList.length})', textScaleFactor: 1.0,),
  97. );
  98. return Column(
  99. children: <Widget>[
  100. _button,
  101. tips,
  102. ],
  103. );
  104. }
  105. @override
  106. Widget build(BuildContext context) {
  107. List<GroupInfoModel> groupList = GroupInfoMgr().groupInfoList;
  108. print('build group chat Page 群数量${groupList.length}');
  109. final List<Widget> _body = [];
  110. _body.add(
  111. ListView.builder(
  112. controller: _scrollController,
  113. itemBuilder: (BuildContext context, int index) {
  114. if (index == 0) {
  115. return _buildCreateButton();
  116. } else {
  117. var info = groupList[index - 1];
  118. return GroupItem(ValueKey(info), groupInfoModel: info);
  119. }
  120. },
  121. itemCount: groupList.length + 1,
  122. ),
  123. );
  124. return Scaffold(
  125. resizeToAvoidBottomPadding: false,
  126. appBar: AppBar(
  127. backgroundColor: AppColors.NewAppbarBgColor,
  128. title: Text(I18n.of(context).group_chat,
  129. textScaleFactor: 1.0, style: Constants.MainTitleStyle),
  130. centerTitle: false,
  131. elevation: 1,
  132. bottom: CustomUI.buildSearchButton(context, () {
  133. Navigator.of(context).push(
  134. new MaterialPageRoute(
  135. builder: (context) {
  136. return GlobalSearchPage(
  137. type: GlobalSearchPageType.SearchGroup,
  138. );
  139. },
  140. ),
  141. );
  142. })),
  143. body: Stack(
  144. children: _body,
  145. ));
  146. }
  147. }