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.
 
 
 
 
 
 

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