rank_people_detail.dart 20 KB

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