Hibok
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

472 řádky
16 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: BorderRadius.only(
  100. 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. // void _selectValue(str) async {
  146. // if (str == 'collection') {
  147. // Map data = {
  148. // "userid": UserData().basicInfo.userId,
  149. // "type": 0,
  150. // "followUserId": this.userId,
  151. // };
  152. // data['sign'] = TokenMgr().getSign(data);
  153. // Response res = await HttpUtil()
  154. // .post('userfollow/follow/insert', data: data, isShowLoading: true);
  155. // Map resData = res.data;
  156. // if (resData['code'] == 0) {
  157. // MessageMgr().emit('refresh_love_list', {'UserId': userId, 'flag': 0});
  158. // showToast(resData['msg']);
  159. // }
  160. // } else if (str == 'cancleCollection') {
  161. // Map data = {
  162. // "userid": UserData().basicInfo.userId,
  163. // "type": 0,
  164. // "followUserId": this.userId,
  165. // };
  166. // data['sign'] = TokenMgr().getSign(data);
  167. // Response res = await HttpUtil()
  168. // .post('userfollow/follow/cancel', data: data, isShowLoading: true);
  169. // Map resData = res.data;
  170. // if (resData['code'] == 0) {
  171. // MessageMgr().emit('refresh_love_list', {'UserId': userId, 'flag': 2});
  172. // showToast(resData['msg']);
  173. // }
  174. // } else if (str == 'black') {
  175. // Map data = {
  176. // "userid": UserData().basicInfo.userId,
  177. // "type": 1,
  178. // "followUserId": this.userId,
  179. // };
  180. // data['sign'] = TokenMgr().getSign(data);
  181. // Response res =
  182. // await HttpUtil().post('userfollow/follow/insert', data: data);
  183. // Map resData = res.data;
  184. // showToast(resData['msg']);
  185. // if (resData['code'] == 0) {
  186. // MessageMgr().emit('refresh_love_list', {'UserId': userId, 'flag': 1});
  187. // }
  188. // } else if (str == 'cancleBlack') {
  189. // var data = {
  190. // "userid": UserData().basicInfo.userId,
  191. // "type": 1,
  192. // "followUserId": this.userId,
  193. // };
  194. // data['sign'] = TokenMgr().getSign(data);
  195. // Response res =
  196. // await HttpUtil().post('userfollow/follow/cancel', data: data);
  197. // Map resData = res.data;
  198. // showToast(resData['msg']);
  199. // if (resData['code'] == 0) {
  200. // MessageMgr().emit('refresh_love_list', {'UserId': userId, 'flag': 2});
  201. // }
  202. // }
  203. // }
  204. //距离、在线以及相册
  205. Widget otherWidget() {
  206. var greyColor = const Color(0xFFB2B2B2);
  207. return Row(
  208. children: <Widget>[
  209. InfoTile(
  210. icon: IconData(0xe630, fontFamily: Constants.IconFontFamily),
  211. title: hiddenDistince
  212. ? I18n.of(context).secrecy
  213. : (UserData().hasLocationPermission
  214. ? WebData().getDistanceString(distance)
  215. : I18n.of(context).unknown),
  216. titleColor: greyColor,
  217. isDivider: true),
  218. InfoTile(
  219. title: isOnline,
  220. titleColor: greyColor,
  221. isDivider: payImg || isHidden),
  222. isHidden
  223. ? InfoTile(
  224. icon: IconData(0xe645, fontFamily: 'iconfont'),
  225. iconHeight: 22,
  226. title: I18n.of(context).application_view,
  227. titleColor: greyColor,
  228. isDivider: false,
  229. onTap: () {
  230. print('click');
  231. })
  232. : Container(),
  233. payImg
  234. ? InfoTile(
  235. icon: IconData(0xe632, fontFamily: Constants.IconFontFamily),
  236. title: I18n.of(context).paid_photo,
  237. titleColor: greyColor,
  238. isDivider: false,
  239. onTap: () {
  240. print('click');
  241. })
  242. : Container(),
  243. ],
  244. );
  245. }
  246. return InkWell(
  247. onTap: () {
  248. // if (sex == UserData().basicInfo.sex) {
  249. // showToast(UserData().basicInfo.sex == 1
  250. // ? I18n.of(context).cant_see
  251. // : I18n.of(context).cant_see2);
  252. // return;
  253. // }
  254. Navigator.of(context).push(
  255. new MaterialPageRoute(
  256. builder: (context) {
  257. return ProfilePage(
  258. userId: userId,
  259. );
  260. },
  261. ),
  262. );
  263. },
  264. child: Container(alignment: Alignment.center,color: AppColors.NewAppbarBgColor,width: Screen.width,child: Container(width: Screen.width-40,child: Column(
  265. crossAxisAlignment: CrossAxisAlignment.center,
  266. children: <Widget>[
  267. SizedBox(height: 23,),
  268. headImg(),
  269. Container(decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.only(
  270. bottomLeft: Radius.circular(15),
  271. bottomRight: Radius.circular(15))) ,child: Column(children: <Widget>[
  272. Container(
  273. //背景
  274. padding: EdgeInsets.only(left: 15,right: 10, bottom: 14.5,top: 5),
  275. child: Column(children: <Widget>[
  276. Stack(
  277. children: <Widget>[
  278. Row(
  279. children: <Widget>[
  280. //头像图片
  281. //信息
  282. Container(
  283. width: MediaQuery.of(context).size.width - 104,
  284. child: Column(
  285. crossAxisAlignment: CrossAxisAlignment.start,
  286. mainAxisAlignment: MainAxisAlignment.end,
  287. children: <Widget>[
  288. nameState(), //名字以及状态
  289. //用户的信息标记
  290. Padding(padding: EdgeInsets.only(top: 9)),
  291. TempUserChips(
  292. city: city,
  293. age: age,
  294. constellation: constellation,
  295. professional: professional),
  296. Padding(padding: EdgeInsets.only(top: 4)),
  297. otherWidget(),
  298. ],
  299. )),
  300. ],
  301. ),
  302. ],
  303. )
  304. ],)),
  305. SizedBox(height: 5,),
  306. Container(
  307. child: //赞
  308. sex == UserData().basicInfo.sex
  309. ? InkWell(
  310. onTap: () {
  311. showToast(UserData().isMan()
  312. ? I18n.of(context).not_love
  313. : I18n.of(context).not_love2);
  314. },
  315. child: Container(
  316. width: 100,
  317. height: 30,
  318. decoration: BoxDecoration(border: Border.all(color: Color(0xFF878787), width: 1),borderRadius: BorderRadius.circular(16)) ,
  319. padding: EdgeInsets.only(
  320. left: 15, right: 15, bottom: 5,top: 5 ),
  321. child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
  322. Icon(
  323. IconData(
  324. 0xe625,
  325. fontFamily: Constants.IconFontFamily,
  326. ),
  327. size: 15,
  328. color: Color(0xffB2B2B2),
  329. ),
  330. SizedBox(width: 5,),
  331. Text('LOVE',style: prefix0.TextStyle(color: Color(0xffB2B2B2)),)
  332. ],)))
  333. : LoveToggle(isActive: isLove,onTap: (bool isActive) async {
  334. Map data = {
  335. "userid": UserData().basicInfo.userId,
  336. "type": 0,
  337. "followUserId": this.userId,
  338. };
  339. data['sign'] = TokenMgr().getSign(data);
  340. if (isActive) {
  341. Response res = await HttpUtil().post(
  342. 'userfollow/follow/insert',
  343. data: data,
  344. isShowLoading: true);
  345. Map resData = res.data;
  346. showToast(resData['msg']);
  347. if (resData['code'] == 0) {
  348. MessageMgr().emit('refresh_love_list',
  349. {'UserId': userId, 'flag': 0});
  350. showToast(resData['msg']);
  351. }
  352. } else {
  353. Response res = await HttpUtil().post(
  354. 'userfollow/follow/cancel',
  355. data: data,
  356. isShowLoading: true);
  357. Map resData = res.data;
  358. if (resData['code'] == 0) {
  359. MessageMgr().emit('refresh_love_list',
  360. {'UserId': userId, 'flag': 2});
  361. showToast(resData['msg']);
  362. }
  363. }
  364. }),
  365. ),
  366. SizedBox(height: 15,),
  367. ],),),
  368. ],
  369. ),),));
  370. }
  371. }
  372. const double TileHeight = 14;
  373. class InfoTile extends StatelessWidget {
  374. @required
  375. final String title;
  376. final Color titleColor;
  377. final IconData icon;
  378. final double iconHeight;
  379. final VoidCallback onTap;
  380. final bool isDivider;
  381. const InfoTile(
  382. {Key key,
  383. this.title,
  384. this.titleColor,
  385. this.icon,
  386. this.onTap,
  387. this.iconHeight: TileHeight,
  388. this.isDivider = false})
  389. : super(key: key);
  390. @override
  391. Widget build(BuildContext context) {
  392. List<Widget> elements = [];
  393. if (icon != null) {
  394. elements.add(Padding(
  395. padding: EdgeInsets.only(bottom: 2),
  396. child: Icon(icon, size: TileHeight, color: titleColor)));
  397. }
  398. elements.add(
  399. Container(
  400. constraints: BoxConstraints(maxWidth: 140),
  401. padding: EdgeInsets.only(right: 5),
  402. child: Text(title,
  403. textScaleFactor: 1.0,
  404. style: TextStyle(
  405. fontSize: 11,
  406. color: titleColor,
  407. fontWeight: FontWeight.normal),
  408. textAlign: TextAlign.center)),
  409. );
  410. if (isDivider) {
  411. elements.add(Container(
  412. height: 12,
  413. child: VerticalDivider(
  414. width: 1,
  415. indent: 0,
  416. endIndent: 0,
  417. color: Colors.black26,
  418. )));
  419. }
  420. var tileWidget = Container(
  421. padding: EdgeInsets.only(right: 5),
  422. child: Row(
  423. //crossAxisAlignment: CrossAxisAlignment.start,
  424. children: elements,
  425. ));
  426. if (onTap != null) {
  427. return InkWell(
  428. child: tileWidget,
  429. onTap: onTap,
  430. );
  431. } else {
  432. return tileWidget;
  433. }
  434. }
  435. }