main_friend_item.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import 'dart:ui';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:get/get_rx/src/rx_types/rx_types.dart';
  6. import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
  7. import 'package:location/data/bean/member_status_info.dart';
  8. import 'package:location/data/bean/user_info.dart';
  9. import 'package:location/resource/colors.gen.dart';
  10. import 'package:location/utils/common_expand.dart';
  11. import '../../data/consts/constants.dart';
  12. import '../../resource/assets.gen.dart';
  13. import '../../resource/string.gen.dart';
  14. import '../../utils/common_style.dart';
  15. import '../../utils/common_util.dart';
  16. import '../../widget/marquee_text.dart';
  17. import '../../widget/relative_time_text.dart';
  18. typedef OnViewTraceClick = void Function(UserInfo userInfo);
  19. Widget buildSelectFriendInfoView(
  20. UserInfo userInfo, Rxn<MemberStatusInfo> memberStatusInfo,
  21. {OnViewTraceClick? onTraceClick}) {
  22. return Container(
  23. width: 336.w,
  24. height: 68.h,
  25. decoration: BoxDecoration(
  26. color: ColorName.white,
  27. borderRadius: BorderRadius.all(Radius.circular(10.r))),
  28. child: Stack(
  29. children: [
  30. Positioned(
  31. top: 0,
  32. bottom: 0,
  33. right: 0,
  34. child: Assets.images.bgMainFriendCard
  35. .image(height: double.infinity)),
  36. Row(
  37. children: [
  38. SizedBox(width: 12.w),
  39. Container(
  40. width: 38.w,
  41. height: 38.w,
  42. decoration: BoxDecoration(
  43. shape: BoxShape.circle,
  44. border: Border.all(color: ColorName.black5, width: 0.5.w)),
  45. child: buildCustomAvatarOrDefaultAvatarView(
  46. size: double.infinity,
  47. avatar: userInfo.avatar,
  48. isMine: userInfo.isMine == true),
  49. ),
  50. SizedBox(width: 5.w),
  51. Expanded(
  52. child: Column(
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: [
  56. Spacer(),
  57. Row(
  58. children: [
  59. ConstrainedBox(
  60. constraints: BoxConstraints(
  61. maxWidth: 0.26.sw,
  62. ),
  63. child: Text(
  64. maxLines: 1,
  65. userInfo.getUserNickName(),
  66. overflow: TextOverflow.ellipsis,
  67. style: TextStyle(
  68. fontWeight: FontWeight.bold,
  69. fontSize: 14.sp,
  70. color: '#202020'.color),
  71. ),
  72. ),
  73. SizedBox(width: 8.w),
  74. Obx(() {
  75. return RelativeTimeText(
  76. timestamp:
  77. userInfo.lastLocation.value?.lastUpdateTime,
  78. updateInterval: Duration(minutes: 1),
  79. style: TextStyle(
  80. fontSize: 11.sp, color: ColorName.black30));
  81. })
  82. ],
  83. ),
  84. SizedBox(height: 5.w),
  85. Expanded(
  86. child: Container(
  87. margin: EdgeInsets.only(right: 12.w),
  88. child: Obx(() {
  89. return ImageFiltered(
  90. enabled: userInfo.blockedMe == true ||
  91. ((memberStatusInfo.value == null ||
  92. memberStatusInfo.value?.expired ==
  93. true) &&
  94. !(userInfo.isMine == true)),
  95. imageFilter: ImageFilter.blur(
  96. sigmaX: Constants.blurredX,
  97. sigmaY: Constants.blurredY,
  98. ),
  99. child: userInfo.blockedMe == true ||
  100. ((memberStatusInfo.value == null ||
  101. memberStatusInfo.value?.expired ==
  102. true) &&
  103. !(userInfo.isMine == true))
  104. ? Text(
  105. addressCheck(
  106. userInfo.lastLocation.value?.address),
  107. style: TextStyle(
  108. fontSize: 12.sp,
  109. color: ColorName.black50))
  110. : MarqueeText(
  111. text: addressCheck(
  112. userInfo.lastLocation.value?.address),
  113. textStyle: TextStyle(
  114. fontSize: 12.sp,
  115. color: ColorName.black50)),
  116. );
  117. }),
  118. ),
  119. ),
  120. Spacer(),
  121. ],
  122. ),
  123. ),
  124. GestureDetector(
  125. onTap: () {
  126. onTraceClick?.call(userInfo);
  127. },
  128. child: Container(
  129. decoration: BoxDecoration(
  130. borderRadius: BorderRadius.circular(8.w),
  131. gradient: LinearGradient(
  132. stops: [0.6, 1],
  133. begin: Alignment.topLeft,
  134. end: Alignment.bottomRight,
  135. colors: [
  136. '#6567EA'.color,
  137. '#41E3C5'.color,
  138. ])),
  139. margin: EdgeInsets.only(right: 12.w),
  140. padding:
  141. EdgeInsets.symmetric(horizontal: 10.w, vertical: 8.w),
  142. child: Row(
  143. mainAxisAlignment: MainAxisAlignment.center,
  144. children: [
  145. Assets.images.iconMainTrackLocation
  146. .image(width: 8.w, height: 8.w),
  147. SizedBox(width: 2.w),
  148. Text(StringName.locationTrace,
  149. style:
  150. TextStyle(fontSize: 11.sp, color: Colors.white))
  151. ],
  152. )),
  153. ),
  154. ],
  155. )
  156. ],
  157. ));
  158. }
  159. Widget mainFriendItem(UserInfo userInfo, bool isSelected,
  160. {required VoidCallback onTap}) {
  161. return GestureDetector(
  162. onTap: onTap,
  163. child: Container(
  164. margin: EdgeInsets.only(right: 12.w),
  165. child: Stack(
  166. children: [
  167. Container(
  168. decoration: BoxDecoration(
  169. color: ColorName.white,
  170. shape: BoxShape.circle,
  171. border: isSelected
  172. ? Border.all(color: ColorName.colorPrimary, width: 2.w)
  173. : null),
  174. width: 52.w,
  175. height: 52.w,
  176. child: Center(
  177. child: buildCustomAvatarOrDefaultAvatarView(
  178. size: 44.w,
  179. avatar: userInfo.avatar,
  180. isMine: userInfo.isMine == true))),
  181. Positioned(
  182. left: 3.w,
  183. bottom: 0,
  184. right: 3.w,
  185. child: Container(
  186. height: 16.w,
  187. padding: EdgeInsets.symmetric(horizontal: 2.w),
  188. decoration: BoxDecoration(
  189. color: ColorName.white,
  190. borderRadius: BorderRadius.circular(10.w),
  191. border: Border.all(color: '#E8E8E8'.color, width: 1.w),
  192. ),
  193. child: Builder(builder: (context) {
  194. String nickName = userNickName(
  195. userInfo.remark, userInfo.phoneNumber, !isSelected);
  196. TextStyle style =
  197. TextStyle(fontSize: 10.sp, color: ColorName.black80);
  198. return Center(
  199. child: isSelected
  200. ? MarqueeText(
  201. text: nickName,
  202. textStyle: TextStyle(
  203. fontSize: 10.sp, color: ColorName.black80))
  204. : Text(nickName, style: style),
  205. );
  206. }),
  207. ),
  208. )
  209. ],
  210. ),
  211. ),
  212. );
  213. }