Hibok
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

210 satır
6.8 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. placeholder: (context, url) => Image.asset(
  53. Constants.DefaultHeadImgUrl,
  54. width: Constants.ContactAvatarSize,
  55. height: Constants.ContactAvatarSize,
  56. ),
  57. width: Constants.ContactAvatarSize,
  58. height: Constants.ContactAvatarSize,
  59. ));
  60. } else {
  61. _avatarIcon = Container(
  62. width: Constants.ContactAvatarSize,
  63. height: Constants.ContactAvatarSize,
  64. decoration: BoxDecoration(
  65. gradient: gradient, borderRadius: BorderRadius.circular(6)),
  66. child: Icon(
  67. IconData(this.iconCode, fontFamily: Constants.IconFontFamily),
  68. color: Colors.white,
  69. ),
  70. );
  71. }
  72. Widget _button = Container(
  73. padding: const EdgeInsets.symmetric(
  74. vertical: MARGIN_VERTICAL, horizontal: 16.0),
  75. decoration: BoxDecoration(color: Colors.white),
  76. child: Row(
  77. children: <Widget>[
  78. _avatarIcon,
  79. SizedBox(width: 10.0),
  80. Expanded(
  81. child: Container(
  82. child: Text(
  83. title,
  84. overflow: TextOverflow.ellipsis,
  85. )))
  86. ],
  87. ),
  88. );
  89. if (userId != 0) {
  90. _button = Dismissible(
  91. key: Key(userId.toString()),
  92. child: _button,
  93. direction: DismissDirection.endToStart,
  94. background: Container(
  95. color: Colors.red,
  96. child: Row(
  97. mainAxisAlignment: MainAxisAlignment.end,
  98. children: <Widget>[
  99. fixedText(I18n.of(context).delete, color: Colors.white),
  100. Icon(
  101. Icons.delete,
  102. color: Colors.white,
  103. ),
  104. SizedBox(width: 20),
  105. ],
  106. ),
  107. ),
  108. confirmDismiss: (direction) async {
  109. var _confirmContent = I18n.of(context).confirm_delete;
  110. // CustomUI.buildOneConfirm(
  111. // context, _confirmContent, I18n.of(context).determine, () async {
  112. // Map data = {
  113. // "userId": UserData().basicInfo.userId,
  114. // "friendsUserId": userId,
  115. // };
  116. // data['sign'] = TokenMgr().getSign(data);
  117. // Response res = await HttpUtil().post('friendship/delete/friends',
  118. // data: data, isShowLoading: true);
  119. // Map resData = res.data;
  120. // showToast(resData['msg']);
  121. // if (resData['code'] == 0) {
  122. // FriendListMgr().delteFriend(userId);
  123. // MessageMgr().emit('Delete friend');
  124. // }
  125. // Navigator.of(context).pop(true);
  126. // });
  127. //return false;
  128. bool isDismiss = await CustomUI.showIosDialog(
  129. context, _confirmContent, () async {
  130. Map data = {
  131. "userId": UserData().basicInfo.userId,
  132. "friendsUserId": userId,
  133. };
  134. data['sign'] = TokenMgr().getSign(data);
  135. Response res = await HttpUtil().post('friendship/delete/friends',
  136. data: data, isShowLoading: true);
  137. Map resData = res.data;
  138. showToast(resData['msg']);
  139. if (resData['code'] == 0) {
  140. FriendListMgr().delteFriend(userId);
  141. MessageMgr().emit('Delete friend');
  142. }
  143. Navigator.of(context).pop(true);
  144. }, () {
  145. Navigator.of(context).pop(false);
  146. });
  147. return isDismiss;
  148. });
  149. }
  150. //分组标签
  151. Widget _itemBody;
  152. if (this.groupTitle != null) {
  153. _itemBody = Column(
  154. children: <Widget>[
  155. Container(
  156. height: GROUP_TITLE_HEIGHT,
  157. padding: EdgeInsets.only(left: 16.0, right: 16.0),
  158. color: const Color(AppColors.ContactGroupTitleBgColor),
  159. alignment: Alignment.centerLeft,
  160. child:
  161. Text(this.groupTitle, style: AppStyles.GroupTitleItemTextStyle),
  162. ),
  163. _button,
  164. ],
  165. );
  166. } else {
  167. _itemBody = _button;
  168. }
  169. return InkWell(
  170. onTap: onPressed == null
  171. ? () {
  172. Navigator.of(context).push(
  173. new MaterialPageRoute(
  174. builder: (context) {
  175. return ProfilePage(
  176. userId: userId,
  177. );
  178. },
  179. ),
  180. );
  181. }
  182. : onPressed,
  183. child: Container(
  184. color: Colors.white,
  185. child: Column(
  186. children: <Widget>[
  187. _itemBody,
  188. isShowDivder
  189. ? Container(
  190. height: 1,
  191. color: const Color(0xFFF3F3F3),
  192. margin: EdgeInsets.only(
  193. left: 26 + Constants.ContactAvatarSize),
  194. )
  195. : Container()
  196. ],
  197. )));
  198. }
  199. }