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.
 
 
 
 
 
 

200 lines
6.4 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/UserData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/home/ProfilePage.dart';
  6. import 'package:chat/utils/CustomUI.dart';
  7. import 'package:chat/utils/HttpUtil.dart';
  8. import 'package:chat/utils/MessageMgr.dart';
  9. import 'package:chat/utils/TokenMgr.dart';
  10. import 'package:chat/utils/friend_list_mgr.dart';
  11. import 'package:chat/utils/screen.dart';
  12. import 'package:dio/dio.dart';
  13. import 'package:flutter/material.dart';
  14. import 'package:oktoast/oktoast.dart';
  15. class FriendsInfo extends StatelessWidget {
  16. FriendsInfo({
  17. @required this.avatar,
  18. @required this.title,
  19. @required this.userId,
  20. this.groupTitle,
  21. this.onPressed,
  22. this.gradient,
  23. this.iconCode,
  24. this.isShowDivder: true,
  25. });
  26. final int userId;
  27. final int iconCode;
  28. final String avatar;
  29. final String title;
  30. final String groupTitle;
  31. final VoidCallback onPressed;
  32. final Gradient gradient;
  33. final bool isShowDivder;
  34. static double height(bool hasGroupTitle) {
  35. final _buttonHeight = MARGIN_VERTICAL * 2 +
  36. Constants.ContactAvatarSize +
  37. Constants.DividerWidth;
  38. if (hasGroupTitle) {
  39. return _buttonHeight + GROUP_TITLE_HEIGHT;
  40. } else {
  41. return _buttonHeight;
  42. }
  43. }
  44. @override
  45. Widget build(BuildContext context) {
  46. Widget _avatarIcon;
  47. if (iconCode == null) {
  48. _avatarIcon = ClipRRect(
  49. borderRadius: BorderRadius.circular(6),
  50. child: CachedNetworkImage(
  51. imageUrl: this.avatar,
  52. width: Constants.ContactAvatarSize,
  53. height: Constants.ContactAvatarSize,
  54. ));
  55. } else {
  56. _avatarIcon = Container(
  57. width: Constants.ContactAvatarSize,
  58. height: Constants.ContactAvatarSize,
  59. decoration: BoxDecoration(
  60. gradient: gradient, borderRadius: BorderRadius.circular(6)),
  61. child: Icon(
  62. IconData(this.iconCode, fontFamily: Constants.IconFontFamily),
  63. color: Colors.white,
  64. ),
  65. );
  66. }
  67. Widget _button = Container(
  68. padding: const EdgeInsets.symmetric(
  69. vertical: MARGIN_VERTICAL, horizontal: 16.0),
  70. decoration: BoxDecoration(color: Colors.white),
  71. child: Row(
  72. children: <Widget>[
  73. _avatarIcon,
  74. SizedBox(width: 10.0),
  75. Text(title),
  76. ],
  77. ),
  78. );
  79. if (userId != 0) {
  80. _button = Dismissible(
  81. key: Key(userId.toString()),
  82. child: _button,
  83. direction: DismissDirection.endToStart,
  84. background: Container(
  85. color: Colors.red,
  86. child: Row(
  87. mainAxisAlignment: MainAxisAlignment.end,
  88. children: <Widget>[
  89. fixedText(I18n.of(context).delete, color: Colors.white),
  90. Icon(
  91. Icons.delete,
  92. color: Colors.white,
  93. ),
  94. SizedBox(width: 20),
  95. ],
  96. ),
  97. ),
  98. confirmDismiss: (direction) async {
  99. var _confirmContent = I18n.of(context).confirm_delete;
  100. // CustomUI.buildOneConfirm(
  101. // context, _confirmContent, I18n.of(context).determine, () async {
  102. // Map data = {
  103. // "userId": UserData().basicInfo.userId,
  104. // "friendsUserId": userId,
  105. // };
  106. // data['sign'] = TokenMgr().getSign(data);
  107. // Response res = await HttpUtil().post('friendship/delete/friends',
  108. // data: data, isShowLoading: true);
  109. // Map resData = res.data;
  110. // showToast(resData['msg']);
  111. // if (resData['code'] == 0) {
  112. // FriendListMgr().delteFriend(userId);
  113. // MessageMgr().emit('Delete friend');
  114. // }
  115. // Navigator.of(context).pop(true);
  116. // });
  117. //return false;
  118. bool isDismiss = await CustomUI.showIosDialog(
  119. context, _confirmContent, () async {
  120. Map data = {
  121. "userId": UserData().basicInfo.userId,
  122. "friendsUserId": userId,
  123. };
  124. data['sign'] = TokenMgr().getSign(data);
  125. Response res = await HttpUtil().post('friendship/delete/friends',
  126. data: data, isShowLoading: true);
  127. Map resData = res.data;
  128. showToast(resData['msg']);
  129. if (resData['code'] == 0) {
  130. FriendListMgr().delteFriend(userId);
  131. MessageMgr().emit('Delete friend');
  132. }
  133. Navigator.of(context).pop(true);
  134. }, () {
  135. Navigator.of(context).pop(false);
  136. });
  137. return isDismiss;
  138. });
  139. }
  140. //分组标签
  141. Widget _itemBody;
  142. if (this.groupTitle != null) {
  143. _itemBody = Column(
  144. children: <Widget>[
  145. Container(
  146. height: GROUP_TITLE_HEIGHT,
  147. padding: EdgeInsets.only(left: 16.0, right: 16.0),
  148. color: const Color(AppColors.ContactGroupTitleBgColor),
  149. alignment: Alignment.centerLeft,
  150. child:
  151. Text(this.groupTitle, style: AppStyles.GroupTitleItemTextStyle),
  152. ),
  153. _button,
  154. ],
  155. );
  156. } else {
  157. _itemBody = _button;
  158. }
  159. return InkWell(
  160. onTap: onPressed == null
  161. ? () {
  162. Navigator.of(context).push(
  163. new MaterialPageRoute(
  164. builder: (context) {
  165. return ProfilePage(
  166. userId: userId,
  167. );
  168. },
  169. ),
  170. );
  171. }
  172. : onPressed,
  173. child: Container(
  174. color: Colors.white,
  175. child: Column(
  176. children: <Widget>[
  177. _itemBody,
  178. isShowDivder
  179. ? Container(
  180. height: 1,
  181. color: const Color(0xFFF3F3F3),
  182. margin: EdgeInsets.only(
  183. left: 26 + Constants.ContactAvatarSize),
  184. )
  185. : Container()
  186. ],
  187. )));
  188. }
  189. }