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.
 
 
 
 
 
 

430 line
15 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/WebData.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/LoveToggle.dart';
  7. import 'package:chat/utils/MessageMgr.dart';
  8. import 'package:chat/utils/screen.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/material.dart' as prefix0;
  11. import 'package:oktoast/oktoast.dart';
  12. import '../utils/HttpUtil.dart';
  13. import 'package:dio/dio.dart';
  14. import "../data/UserData.dart";
  15. import '../utils/TokenMgr.dart';
  16. import 'TempUserChips.dart';
  17. class TempUserCard extends StatelessWidget {
  18. final String userName;
  19. final bool isReal;
  20. final String city; //城市
  21. final int age; //年龄
  22. final String constellation; //星座
  23. final String professional; //职业
  24. final String isOnline;
  25. final double distance;
  26. final int userId;
  27. final bool isLove;
  28. final bool isBalck;
  29. final String headUrl;
  30. final bool payImg;
  31. final int imgNum;
  32. final int sex;
  33. final bool isHidden;
  34. final int member;
  35. final bool hiddenDistince;
  36. final int nameSize;
  37. TempUserCard(
  38. {Key key,
  39. this.userName,
  40. this.isReal: false,
  41. this.city,
  42. this.age,
  43. this.constellation,
  44. this.professional,
  45. this.isOnline,
  46. this.distance,
  47. this.userId,
  48. this.isLove: false,
  49. this.sex,
  50. this.headUrl: '',
  51. this.payImg: false,
  52. this.imgNum: 0,
  53. this.isHidden: false,
  54. this.member: 0,
  55. this.hiddenDistince: false,
  56. this.nameSize = 8,
  57. this.isBalck: false})
  58. : super(key: key);
  59. @override
  60. Widget build(BuildContext context) {
  61. bool isVIP = member > 0;
  62. bool isSVIP = member == 2;
  63. //头像
  64. Widget headImg() {
  65. double height = Screen.width;
  66. return Stack(
  67. children: <Widget>[
  68. Container(
  69. height: height - 40,
  70. width: height - 40,
  71. child: ClipRRect(
  72. borderRadius: BorderRadius.only(
  73. topLeft: Radius.circular(15),
  74. topRight: Radius.circular(15)),
  75. child: headUrl == '' || headUrl == null
  76. ? Image.asset(
  77. Constants.DefaultHeadImgUrl,
  78. width: height - 40,
  79. height: height - 40,
  80. )
  81. : CachedNetworkImage(
  82. imageUrl: headUrl,
  83. placeholder: (context, url) => Image.asset(
  84. Constants.DefaultHeadImgUrl,
  85. width: height - 40,
  86. height: height - 40,
  87. ),
  88. fit: BoxFit.cover,
  89. )),
  90. ),
  91. Positioned(
  92. left: 0,
  93. bottom: 0,
  94. child: Container(
  95. height: 27,
  96. width: 54,
  97. decoration: BoxDecoration(
  98. color: Colors.black54,
  99. borderRadius:
  100. BorderRadius.only(topRight: Radius.circular(10))),
  101. child: Row(
  102. //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  103. children: <Widget>[
  104. Padding(
  105. padding: EdgeInsets.only(left: 6),
  106. child:
  107. Icon(Icons.image, size: 15, color: Colors.white)),
  108. Padding(
  109. padding: EdgeInsets.only(left: 5, top: 2),
  110. child: fixedText(imgNum.toString(),
  111. color: Colors.white, fontSize: 14),
  112. ),
  113. ],
  114. ),
  115. ))
  116. ],
  117. );
  118. }
  119. //名字以及认证状态
  120. Widget nameState() {
  121. return Row(
  122. children: <Widget>[
  123. fixedText(WebData().subUserName(userName, size: nameSize),
  124. fontSize: 15),
  125. isReal && sex == 2
  126. ? Container(
  127. margin: EdgeInsets.only(left: 5),
  128. padding:
  129. EdgeInsets.only(top: 2, bottom: 2, left: 5, right: 5),
  130. alignment: Alignment.center,
  131. decoration: BoxDecoration(
  132. borderRadius: BorderRadius.circular(10),
  133. color: Constants.PurpleBackgroundColor,
  134. ),
  135. child: fixedText('Real', fontSize: 8, color: Colors.white))
  136. : Container(),
  137. isVIP && sex == 1
  138. ? Container(
  139. margin: EdgeInsets.only(left: 5),
  140. child: isSVIP ? Constants.svipIcon : Constants.vipIcon)
  141. : Container(),
  142. ],
  143. );
  144. }
  145. //距离、在线以及相册
  146. Widget otherWidget() {
  147. var greyColor = const Color(0xFFB2B2B2);
  148. return Row(
  149. children: <Widget>[
  150. InfoTile(
  151. icon: IconData(0xe630, fontFamily: Constants.IconFontFamily),
  152. title: hiddenDistince
  153. ? I18n.of(context).secrecy
  154. : (UserData().hasLocationPermission
  155. ? WebData().getDistanceString(distance)
  156. : I18n.of(context).unknown),
  157. titleColor: greyColor,
  158. isDivider: true),
  159. InfoTile(
  160. title: isOnline,
  161. titleColor: greyColor,
  162. isDivider: payImg || isHidden),
  163. isHidden
  164. ? InfoTile(
  165. icon: IconData(0xe645, fontFamily: 'iconfont'),
  166. iconHeight: 22,
  167. title: I18n.of(context).application_view,
  168. titleColor: greyColor,
  169. isDivider: false,
  170. onTap: () {
  171. print('click');
  172. })
  173. : Container(),
  174. payImg
  175. ? InfoTile(
  176. icon: IconData(0xe632, fontFamily: Constants.IconFontFamily),
  177. title: I18n.of(context).paid_photo,
  178. titleColor: greyColor,
  179. isDivider: false,
  180. onTap: () {
  181. print('click');
  182. })
  183. : Container(),
  184. ],
  185. );
  186. }
  187. return InkWell(
  188. onTap: () {
  189. // if (sex == UserData().basicInfo.sex) {
  190. // showToast(UserData().basicInfo.sex == 1
  191. // ? I18n.of(context).cant_see
  192. // : I18n.of(context).cant_see2);
  193. // return;
  194. // }
  195. Navigator.of(context).push(
  196. new MaterialPageRoute(
  197. builder: (context) {
  198. return ProfilePage(
  199. userId: userId,
  200. );
  201. },
  202. ),
  203. );
  204. },
  205. child: Container(
  206. alignment: Alignment.center,
  207. color: AppColors.NewAppbarBgColor,
  208. width: Screen.width,
  209. child: Container(
  210. width: Screen.width - 40,
  211. child: Column(
  212. crossAxisAlignment: CrossAxisAlignment.center,
  213. children: <Widget>[
  214. SizedBox(
  215. height: 23,
  216. ),
  217. headImg(),
  218. Container(
  219. decoration: BoxDecoration(
  220. color: Colors.white,
  221. borderRadius: BorderRadius.only(
  222. bottomLeft: Radius.circular(15),
  223. bottomRight: Radius.circular(15))),
  224. child: Column(
  225. children: <Widget>[
  226. Container(
  227. //背景
  228. padding: EdgeInsets.only(
  229. left: 15, right: 10, bottom: 14.5, top: 5),
  230. child: Column(
  231. children: <Widget>[
  232. Stack(
  233. children: <Widget>[
  234. Row(
  235. children: <Widget>[
  236. //头像图片
  237. //信息
  238. Container(
  239. width: MediaQuery.of(context)
  240. .size
  241. .width -
  242. 104,
  243. child: Column(
  244. crossAxisAlignment:
  245. CrossAxisAlignment.start,
  246. mainAxisAlignment:
  247. MainAxisAlignment.end,
  248. children: <Widget>[
  249. nameState(), //名字以及状态
  250. //用户的信息标记
  251. Padding(
  252. padding:
  253. EdgeInsets.only(top: 9)),
  254. TempUserChips(
  255. city: city,
  256. age: age,
  257. constellation: constellation,
  258. professional: professional),
  259. Padding(
  260. padding:
  261. EdgeInsets.only(top: 4)),
  262. otherWidget(),
  263. ],
  264. )),
  265. ],
  266. ),
  267. ],
  268. )
  269. ],
  270. )),
  271. SizedBox(
  272. height: 5,
  273. ),
  274. Container(
  275. child: //赞
  276. sex == UserData().basicInfo.sex
  277. ? InkWell(
  278. onTap: () {
  279. showToast(UserData().isMan()
  280. ? I18n.of(context).not_love
  281. : I18n.of(context).not_love2);
  282. },
  283. child: Container(
  284. width: 100,
  285. height: 30,
  286. decoration: BoxDecoration(
  287. border: Border.all(
  288. color: Color(0xFF878787),
  289. width: 1),
  290. borderRadius:
  291. BorderRadius.circular(16)),
  292. padding: EdgeInsets.only(
  293. left: 15,
  294. right: 15,
  295. bottom: 5,
  296. top: 5),
  297. child: Row(
  298. mainAxisAlignment:
  299. MainAxisAlignment.center,
  300. children: <Widget>[
  301. Icon(
  302. IconData(
  303. 0xe625,
  304. fontFamily:
  305. Constants.IconFontFamily,
  306. ),
  307. size: 15,
  308. color: Color(0xffB2B2B2),
  309. ),
  310. SizedBox(
  311. width: 5,
  312. ),
  313. Text(
  314. 'LOVE',
  315. style: prefix0.TextStyle(
  316. color: Color(0xffB2B2B2)),
  317. )
  318. ],
  319. )))
  320. : LoveToggle(
  321. isActive: isLove,
  322. onTap: (bool isActive) async {
  323. if (isActive) {
  324. HttpUtil().setLove(userId, () {
  325. MessageMgr().emit('refresh_love_list',
  326. {'UserId': userId, 'flag': 0});
  327. });
  328. } else {
  329. HttpUtil().cancleLove(userId, () {
  330. MessageMgr().emit('refresh_love_list',
  331. {'UserId': userId, 'flag': 2});
  332. });
  333. }
  334. }),
  335. ),
  336. SizedBox(
  337. height: 15,
  338. ),
  339. ],
  340. ),
  341. ),
  342. ],
  343. ),
  344. ),
  345. ));
  346. }
  347. }
  348. const double TileHeight = 14;
  349. class InfoTile extends StatelessWidget {
  350. @required
  351. final String title;
  352. final Color titleColor;
  353. final IconData icon;
  354. final double iconHeight;
  355. final VoidCallback onTap;
  356. final bool isDivider;
  357. const InfoTile(
  358. {Key key,
  359. this.title,
  360. this.titleColor,
  361. this.icon,
  362. this.onTap,
  363. this.iconHeight: TileHeight,
  364. this.isDivider = false})
  365. : super(key: key);
  366. @override
  367. Widget build(BuildContext context) {
  368. List<Widget> elements = [];
  369. if (icon != null) {
  370. elements.add(Padding(
  371. padding: EdgeInsets.only(bottom: 2),
  372. child: Icon(icon, size: TileHeight, color: titleColor)));
  373. }
  374. elements.add(
  375. Container(
  376. constraints: BoxConstraints(maxWidth: 140),
  377. padding: EdgeInsets.only(right: 5),
  378. child: Text(title,
  379. textScaleFactor: 1.0,
  380. style: TextStyle(
  381. fontSize: 11,
  382. color: titleColor,
  383. fontWeight: FontWeight.normal),
  384. textAlign: TextAlign.center)),
  385. );
  386. if (isDivider) {
  387. elements.add(Container(
  388. height: 12,
  389. child: VerticalDivider(
  390. width: 1,
  391. indent: 0,
  392. endIndent: 0,
  393. color: Colors.black26,
  394. )));
  395. }
  396. var tileWidget = Container(
  397. padding: EdgeInsets.only(right: 5),
  398. child: Row(
  399. //crossAxisAlignment: CrossAxisAlignment.start,
  400. children: elements,
  401. ));
  402. if (onTap != null) {
  403. return InkWell(
  404. child: tileWidget,
  405. onTap: onTap,
  406. );
  407. } else {
  408. return tileWidget;
  409. }
  410. }
  411. }