rank_people_detail.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:sport/bean/rank_game_info.dart';
  5. import 'package:sport/bean/user.dart';
  6. import 'package:sport/bean/user_info.dart';
  7. import 'package:sport/pages/social/chat_page.dart';
  8. import 'package:sport/pages/social/private_message_page.dart';
  9. import 'package:sport/router/navigator_util.dart';
  10. import 'package:sport/services/api/inject_api.dart';
  11. import 'package:sport/services/userid.dart';
  12. import 'package:sport/utils/toast.dart';
  13. import 'package:sport/widgets/appbar.dart';
  14. import 'package:sport/widgets/button_primary.dart';
  15. import 'package:sport/widgets/dialog/request_dialog.dart';
  16. import 'package:sport/widgets/image.dart';
  17. import 'package:sport/widgets/misc.dart';
  18. import 'package:sport/widgets/space.dart';
  19. class RankPeopleDetailsPage extends StatefulWidget {
  20. final User _data;
  21. RankPeopleDetailsPage(this._data);
  22. @override
  23. State<StatefulWidget> createState() {
  24. return _RankPeopleDetailsPageState();
  25. }
  26. }
  27. class _RankPeopleDetailsPageState extends State<RankPeopleDetailsPage> with InjectApi, UserId {
  28. ValueNotifier<UserInfo> _valueNotifierUserInfo;
  29. @override
  30. void initState() {
  31. super.initState();
  32. _valueNotifierUserInfo = ValueNotifier(UserInfo.fromJson(widget._data.toJson()));
  33. api.getUserInfo("${widget._data.userId}").then((value) {
  34. _valueNotifierUserInfo.value = value.data;
  35. });
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. final data = widget._data;
  40. return Scaffold(
  41. backgroundColor: Colors.white,
  42. appBar: AppBar(
  43. backgroundColor: Colors.white,
  44. elevation: 0,
  45. leading: buildBackButton(context),
  46. ),
  47. body: SingleChildScrollView(
  48. // physics: ClampingScrollPhysics(),
  49. child: Container(
  50. color: Colors.white,
  51. width: double.infinity,
  52. child: Column(
  53. children: <Widget>[
  54. ValueListenableBuilder(
  55. valueListenable: _valueNotifierUserInfo,
  56. builder: (BuildContext context, UserInfo user, Widget child) {
  57. if (user == null) {
  58. return Container();
  59. }
  60. return Container(
  61. child: Column(
  62. mainAxisSize: MainAxisSize.min,
  63. children: <Widget>[
  64. CircleAvatar(
  65. backgroundImage: userAvatarProvider(user.avatar),
  66. radius: 45,
  67. ),
  68. Space(
  69. height: 12,
  70. ),
  71. Text(user.name, style: Theme.of(context).textTheme.headline1),
  72. Space(
  73. height: 6,
  74. ),
  75. Row(
  76. mainAxisSize: MainAxisSize.min,
  77. children: <Widget>[
  78. Image.asset("lib/assets/img/mine_icon_${user.gender == 1 ? "man" : "girl"}_gray.png"),
  79. Space(
  80. width: 4,
  81. ),
  82. Text(user.gender == 1 ? "男" : "女", style: Theme.of(context).textTheme.bodyText1),
  83. Space(
  84. width: 10,
  85. ),
  86. Text(user.age != null ? "${user.age}岁" : "", style: Theme.of(context).textTheme.bodyText1),
  87. if ((user.districtId ?? 0) != 0)
  88. Padding(
  89. padding: const EdgeInsets.only(left: 10.0),
  90. child: Text("${user.province}${user.province == user.city ? '' : user.city}", style: Theme.of(context).textTheme.bodyText1),
  91. )
  92. ],
  93. ),
  94. if (selfId != '${widget._data.userId}')
  95. Padding(
  96. padding: const EdgeInsets.only(top: 20.0),
  97. child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
  98. PrimaryButton(
  99. width: 120,
  100. height: 35,
  101. callback: () {
  102. // 先尝试换一下
  103. NavigatorUtil.goPage(context, (context) => ChatPage(user));
  104. // NavigatorUtil.goPage(context, (context) => PrivateMessagePage(user));
  105. },
  106. content: '',
  107. child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
  108. Image.asset("lib/assets/img/mine_icon_message.png"),
  109. Space(
  110. width: 6,
  111. ),
  112. Text(
  113. "私信",
  114. strutStyle: fixedLine,
  115. style: Theme.of(context).textTheme.subtitle1.copyWith(color: Colors.white),
  116. )
  117. ]),
  118. ),
  119. Space(
  120. width: 12,
  121. ),
  122. user.followStatus == "friends" || user.followStatus == "followed"
  123. ? GestureDetector(
  124. child: Container(
  125. width: 120,
  126. height: 35,
  127. alignment: Alignment.center,
  128. child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
  129. Image.asset("lib/assets/img/mine_icon_followed.png"),
  130. Space(
  131. width: 6,
  132. ),
  133. Text(
  134. "已关注",
  135. strutStyle: fixedLine,
  136. style: Theme.of(context).textTheme.subtitle1.copyWith(color: Theme.of(context).accentColor),
  137. )
  138. ]),
  139. decoration: BoxDecoration(
  140. borderRadius: BorderRadius.circular(20),
  141. border: Border.all(
  142. color: Theme.of(context).accentColor,
  143. width: .5,
  144. ),
  145. ),
  146. ),
  147. onTap: () async {
  148. await request(context, () async {
  149. var resp = await api.userUnFollow(uid: user.id).catchError((onError) {});
  150. if (resp?.code == 0) {
  151. ToastUtil.show("取关成功");
  152. user.followStatus = "none";
  153. setState(() {});
  154. }
  155. });
  156. },
  157. )
  158. : PrimaryButton(
  159. width: 120,
  160. height: 35,
  161. callback: () async {
  162. await request(context, () async {
  163. var resp = await api.userFollow(uid: user.id).catchError((onError) {});
  164. if (resp?.code == 0) {
  165. ToastUtil.show("关注成功");
  166. user.followStatus = "followed";
  167. setState(() {});
  168. }
  169. });
  170. },
  171. content: '',
  172. child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
  173. Image.asset("lib/assets/img/mine_icon_follow.png"),
  174. Space(
  175. width: 6,
  176. ),
  177. Text(
  178. "关注",
  179. strutStyle: fixedLine,
  180. style: Theme.of(context).textTheme.subtitle1.copyWith(color: Colors.white),
  181. )
  182. ]),
  183. ),
  184. ]),
  185. ),
  186. Space(
  187. height: 32,
  188. ),
  189. ],
  190. ),
  191. );
  192. },
  193. ),
  194. Divider(
  195. endIndent: 12,
  196. indent: 12,
  197. ),
  198. Container(
  199. padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
  200. child: Column(
  201. children: <Widget>[
  202. Padding(
  203. padding: EdgeInsets.only(
  204. bottom: 12.0,
  205. ),
  206. child: Row(
  207. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  208. children: <Widget>[
  209. Text(
  210. "榜单排名",
  211. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  212. ),
  213. Text(
  214. "第 ${data.position} 名",
  215. style: TextStyle(color: Color.fromRGBO(255, 196, 0, 1)),
  216. )
  217. ],
  218. ),
  219. ),
  220. if (data.score != null)
  221. Padding(
  222. padding: EdgeInsets.only(
  223. bottom: 12.0,
  224. ),
  225. child: Row(
  226. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  227. children: <Widget>[
  228. Text(
  229. "通关评分",
  230. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  231. ),
  232. Text(
  233. "${data.score.toStringAsFixed(1)}分",
  234. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  235. )
  236. ],
  237. ),
  238. ),
  239. if (data.sportDay == 0)
  240. Padding(
  241. padding: EdgeInsets.only(
  242. bottom: 12.0,
  243. ),
  244. child: Row(
  245. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  246. children: <Widget>[
  247. Text(
  248. "通关日期",
  249. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  250. ),
  251. Text(
  252. "${data.finishAt}",
  253. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  254. )
  255. ],
  256. ),
  257. ),
  258. if (data.sportDay == 0)
  259. Padding(
  260. padding: EdgeInsets.only(
  261. bottom: 12.0,
  262. ),
  263. child: Row(
  264. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  265. children: <Widget>[
  266. Text(
  267. "通关时长",
  268. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  269. ),
  270. Text(
  271. "${data.duration}分钟",
  272. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  273. )
  274. ],
  275. ),
  276. ),
  277. if (data.sportDay > 0)
  278. Padding(
  279. padding: EdgeInsets.only(
  280. bottom: 12.0,
  281. ),
  282. child: Row(
  283. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  284. children: <Widget>[
  285. Text(
  286. "运动时长",
  287. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  288. ),
  289. Text(
  290. "${data.duration}分钟",
  291. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  292. )
  293. ],
  294. ),
  295. ),
  296. if (data.sportDay > 0)
  297. Padding(
  298. padding: EdgeInsets.only(
  299. bottom: 12.0,
  300. ),
  301. child: Row(
  302. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  303. children: <Widget>[
  304. Text(
  305. "运动天数",
  306. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  307. ),
  308. Text(
  309. "${data.sportDay}天",
  310. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  311. )
  312. ],
  313. ),
  314. ),
  315. if (data.sportDay > 0)
  316. Padding(
  317. padding: EdgeInsets.only(
  318. bottom: 12.0,
  319. ),
  320. child: Row(
  321. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  322. children: <Widget>[
  323. Text(
  324. "每天平均时长",
  325. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  326. ),
  327. Text(
  328. "${data.duration ~/ data.sportDay}分钟/天",
  329. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  330. )
  331. ],
  332. ),
  333. ),
  334. Padding(
  335. padding: EdgeInsets.only(
  336. bottom: 12.0,
  337. ),
  338. child: Row(
  339. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  340. children: <Widget>[
  341. Text(
  342. "消耗能量",
  343. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  344. ),
  345. Text(
  346. "${data.consume} kal",
  347. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  348. )
  349. ],
  350. ),
  351. ),
  352. Padding(
  353. padding: EdgeInsets.only(
  354. bottom: 5.0,
  355. ),
  356. child: Row(
  357. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  358. children: <Widget>[
  359. Text(
  360. "运动效率",
  361. style: TextStyle(color: Color.fromRGBO(51, 51, 51, 1)),
  362. ),
  363. Text(
  364. "${(data.consume / data.duration).toStringAsFixed(2)} kal/min",
  365. style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1)),
  366. )
  367. ],
  368. ),
  369. ),
  370. ],
  371. ),
  372. ),
  373. Divider(
  374. endIndent: 12,
  375. indent: 12,
  376. ),
  377. Column(
  378. children: <Widget>[
  379. Space(
  380. height: 24,
  381. ),
  382. // head
  383. Stack(
  384. alignment: Alignment.center,
  385. children: <Widget>[
  386. Image.asset(
  387. "lib/assets/img/mine_image_achievement.png",
  388. fit: BoxFit.fitWidth,
  389. width: 240,
  390. ),
  391. Text(
  392. "${(widget?._data?.userId?.toString() == selfId) ? "我" : "他"}的成就",
  393. style: Theme.of(context).textTheme.subtitle1,
  394. )
  395. ],
  396. ),
  397. // bottom
  398. Space(
  399. height: 12,
  400. ),
  401. ValueListenableBuilder(
  402. valueListenable: _valueNotifierUserInfo,
  403. builder: (BuildContext context, UserInfo user, Widget child) {
  404. if (user == null) {
  405. return Container();
  406. }
  407. return Padding(padding: EdgeInsets.all(12.0), child: achievementGroupWidget(user.achievements));
  408. },
  409. ),
  410. ],
  411. )
  412. ],
  413. ),
  414. ),
  415. ));
  416. }
  417. }