my_page.dart 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
  3. import 'package:get_it/get_it.dart';
  4. import 'package:nordic_dfu/nordic_dfu.dart';
  5. import 'package:provider/provider.dart';
  6. import 'package:sport/application.dart';
  7. import 'package:sport/bean/UpdateInfo.dart';
  8. import 'package:sport/bean/post_user.dart';
  9. import 'package:sport/pages/home/guide_page.dart';
  10. import 'package:sport/pages/social/user_friend_add_page.dart';
  11. import 'package:sport/pages/social/user_friend_page.dart';
  12. import 'package:sport/pages/social/user_post_page.dart';
  13. import 'package:sport/provider/bluetooth.dart';
  14. import 'package:sport/provider/message_model.dart';
  15. import 'package:sport/provider/user_model.dart';
  16. import 'package:sport/router/navigator_util.dart';
  17. import 'package:sport/router/routes.dart';
  18. import 'package:sport/services/api/inject_api.dart';
  19. import 'package:sport/services/api/resp.dart';
  20. import 'package:sport/utils/update_apk.dart';
  21. import 'package:sport/widgets/decoration.dart';
  22. import 'package:sport/widgets/dialog/search_device.dart';
  23. import 'package:sport/widgets/image.dart';
  24. import 'package:sport/widgets/list_tile.dart';
  25. import 'package:sport/widgets/space.dart';
  26. import 'package:sport/widgets/user_widget.dart';
  27. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  28. class MyPage extends StatefulWidget {
  29. @override
  30. _MyPageState createState() => _MyPageState();
  31. }
  32. class _MyPageState extends State<MyPage> with InjectApi {
  33. @override
  34. void initState() {
  35. super.initState();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. var rowPadding = EdgeInsets.symmetric(horizontal: 20.0);
  40. var textStyle = Theme.of(context).textTheme.subtitle1?.copyWith(fontSize: 16);
  41. return Scaffold(
  42. body: CustomScrollView(
  43. slivers: [
  44. SliverAppBar(
  45. floating: true,
  46. elevation: 0,
  47. expandedHeight: 120.0,
  48. flexibleSpace: FlexibleSpaceBar(
  49. collapseMode: CollapseMode.pin,
  50. background: Container(
  51. color: Colors.white,
  52. child: SafeArea(
  53. child: InkWell(
  54. child: Consumer<UserModel>(
  55. builder: (_, model, __) => Container(
  56. padding: const EdgeInsets.fromLTRB(20.0, 30.0, 20.0, 24.0),
  57. child: Row(
  58. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  59. children: <Widget>[
  60. Row(
  61. children: <Widget>[
  62. InkWell(
  63. onTap: () {
  64. NavigatorUtil.goSocialUserDetail(context, PostUser(id: model.user.id.toString(), name: model.user.name, avatar: model.user.avatar));
  65. },
  66. child: CircleAvatar(
  67. backgroundColor: Colors.black26,
  68. backgroundImage: userAvatarProvider(model.user.avatar),
  69. radius: 30,
  70. ),
  71. ),
  72. Space(
  73. width: 12,
  74. ),
  75. Column(
  76. mainAxisSize: MainAxisSize.min,
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. crossAxisAlignment: CrossAxisAlignment.start,
  79. children: <Widget>[
  80. Text(model.user.name, style: Theme.of(context).textTheme.headline1),
  81. Space(
  82. height: 10,
  83. ),
  84. Row(
  85. crossAxisAlignment: CrossAxisAlignment.baseline,
  86. textBaseline: TextBaseline.alphabetic,
  87. children: <Widget>[
  88. Image.asset("lib/assets/img/mine_icon_${model.user.gender == 1 ? "man" : "girl"}_gray.png"),
  89. Space(
  90. width: 4,
  91. ),
  92. Text(
  93. model.user.gender == 1 ? "男" : "女",
  94. style: Theme.of(context).textTheme.bodyText1,
  95. ),
  96. // if ((model.user.age ?? 0) != 0)
  97. // Padding(
  98. // padding: const EdgeInsets.only(left: 10.0),
  99. // child: Text(
  100. // "${model.user.age}岁",
  101. // style: TextStyle(color: Color(0xff999999), fontSize: 12),
  102. // ),
  103. // ),
  104. if ((model.user.weight ?? 0) != 0)
  105. Padding(
  106. padding: const EdgeInsets.only(left: 10.0),
  107. child: Text(
  108. "${model.user.weight}kg",
  109. style: Theme.of(context).textTheme.bodyText1,
  110. ),
  111. ),
  112. if (model.user.city != null)
  113. Padding(
  114. padding: const EdgeInsets.only(left: 10.0),
  115. child: Text(
  116. "${model.user.province}${model.user.province == model.user.city ? '' : model.user.city}",
  117. style: Theme.of(context).textTheme.bodyText1,
  118. ),
  119. ),
  120. ],
  121. ),
  122. ],
  123. ),
  124. ],
  125. ),
  126. Row(
  127. children: <Widget>[
  128. GestureDetector(
  129. onTap: (){
  130. NavigatorUtil.goPage(context, (context) => UserFriendAddPage());
  131. },
  132. child: Container(
  133. width: 22.0,
  134. height: 22.0,
  135. margin: const EdgeInsets.all(12.0),
  136. child: Image.asset("lib/assets/img/mine_icon_code.png"),
  137. ),
  138. ),
  139. arrowRight5(),
  140. SizedBox(
  141. width: 12.0,
  142. ),
  143. ],
  144. ),
  145. ],
  146. ),
  147. )),
  148. onTap: () => NavigatorUtil.go(context, Routes.userInfo),
  149. ),
  150. ),
  151. ),
  152. ),
  153. ),
  154. SliverToBoxAdapter(
  155. child: Container(
  156. padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 16.0),
  157. child: Column(
  158. children: [
  159. if (isDebugShoe)
  160. Container(
  161. child: ValueListenableBuilder<Map<String, int>>(
  162. valueListenable: GetIt.I<Bluetooth>().timeUseNotifier,
  163. builder: (context, data, _) {
  164. return Text(
  165. "连接用时(ms):${data.isNotEmpty ? data.values.reduce((previousValue, element) => previousValue + element) : 0} = $data",
  166. style: Theme.of(context).textTheme.bodyText1!.copyWith(color: Colors.green),
  167. );
  168. },
  169. ),
  170. padding: EdgeInsets.only(bottom: 12.0),
  171. ),
  172. Container(
  173. padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
  174. decoration: circular(),
  175. child: ListTile(
  176. leading: Image.asset(
  177. "lib/assets/img/mine_image_shoe.png",
  178. height: 32.0,
  179. ),
  180. title: Row(
  181. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  182. children: [
  183. Text(
  184. "我的鞋子",
  185. style: Theme.of(context).textTheme.subtitle1!.copyWith(fontSize: 16.0),
  186. ),
  187. ValueListenableBuilder(
  188. valueListenable: GetIt.I<Bluetooth>().deviceNotifier,
  189. builder: (BuildContext context, DiscoveredDevice? d, Widget? child) {
  190. if (d == null)
  191. return Text(
  192. "未连接",
  193. style: Theme.of(context).textTheme.bodyText2,
  194. );
  195. return Text("已连接", style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Color(0xff27D171)));
  196. },
  197. )
  198. ],
  199. ),
  200. trailing: arrowRight5(),
  201. contentPadding: EdgeInsets.zero,
  202. onTap: () {
  203. if (!GetIt.I<Bluetooth>().isConnected) {
  204. openSearchDeviceDialog(context);
  205. // ToastUtil.show("没连接设备!");
  206. return;
  207. }
  208. NavigatorUtil.go(context, Routes.deviceInfo);
  209. },
  210. ),
  211. ),
  212. Container(
  213. margin: EdgeInsets.only(top: 16.0),
  214. decoration: circular(),
  215. child: ListView(
  216. padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
  217. physics: NeverScrollableScrollPhysics(),
  218. shrinkWrap: true,
  219. children: divideTiles(
  220. context: context,
  221. includeLast: false,
  222. tiles: [
  223. ListTile(
  224. title: Row(
  225. children: [
  226. Image.asset("lib/assets/img/mine_icon_level.png"),
  227. const SizedBox(
  228. width: 8,
  229. ),
  230. Text(
  231. "运动等级",
  232. style: textStyle,
  233. )
  234. ],
  235. ),
  236. contentPadding: rowPadding,
  237. trailing: arrowRight5(),
  238. onTap: () => NavigatorUtil.go(context, Routes.level),
  239. ),
  240. ListTile(
  241. title: Row(
  242. children: [
  243. Image.asset("lib/assets/img/mine_icon_record.png"),
  244. const SizedBox(
  245. width: 8,
  246. ),
  247. Text("运动记录", style: textStyle)
  248. ],
  249. ),
  250. contentPadding: rowPadding,
  251. trailing: arrowRight5(),
  252. onTap: () => NavigatorUtil.go(context, Routes.gamelistpage),
  253. ),
  254. if (openSocial())
  255. ListTile(
  256. title: Row(
  257. children: [
  258. Image.asset("lib/assets/img/mine_icon_invitation.png"),
  259. const SizedBox(
  260. width: 8,
  261. ),
  262. Text("社区帖子", style: textStyle)
  263. ],
  264. ),
  265. contentPadding: rowPadding,
  266. trailing: arrowRight5(),
  267. onTap: () {
  268. var userModel = Provider.of<UserModel>(context, listen: false);
  269. var user = userModel.user;
  270. var postUser = PostUser(id: "${user.id}", name: user.name, avatar: user.avatar);
  271. // NavigatorUtil.goSocialUserDetail(context,postUser);
  272. NavigatorUtil.goPage(context, (context) => UserPostPage(postUser));
  273. },
  274. ),
  275. ListTile(
  276. title: Row(
  277. children: [
  278. Image.asset("lib/assets/img/mine_icon_friend.png"),
  279. const SizedBox(
  280. width: 8,
  281. ),
  282. Text("我的好友", style: textStyle)
  283. ],
  284. ),
  285. contentPadding: rowPadding,
  286. trailing: Row(
  287. mainAxisSize: MainAxisSize.min,
  288. children: [
  289. ValueListenableBuilder(
  290. valueListenable: GetIt.I<MessageModel>().notifierFriendFansList,
  291. builder: (BuildContext context, int value, Widget? child) {
  292. int count = value;
  293. if (count == 0) return Container();
  294. return Positioned(
  295. right: -4,
  296. top: 4,
  297. child: Container(
  298. width: 8,
  299. height: 8,
  300. decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
  301. child: Text(
  302. "$value",
  303. style: Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.white, fontSize: 8),
  304. ),
  305. ),
  306. );
  307. },
  308. ),
  309. arrowRight5(),
  310. ],
  311. ),
  312. onTap: () => NavigatorUtil.goPage(context, (context) => UserFriendPage()),
  313. ),
  314. ],
  315. ).toList(),
  316. ),
  317. ),
  318. Container(
  319. margin: EdgeInsets.only(top: 16.0),
  320. decoration: circular(),
  321. child: ListView(
  322. padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
  323. physics: NeverScrollableScrollPhysics(),
  324. shrinkWrap: true,
  325. children: divideTiles(
  326. context: context,
  327. includeLast: false,
  328. tiles: [
  329. ListTile(
  330. title: Row(
  331. children: [
  332. Image.asset("lib/assets/img/mine_icon_feedback.png"),
  333. const SizedBox(
  334. width: 8,
  335. ),
  336. Text("用户反馈", style: textStyle),
  337. ],
  338. ),
  339. contentPadding: rowPadding,
  340. trailing: arrowRight5(),
  341. onTap: () => NavigatorUtil.go(context, Routes.feedback),
  342. ),
  343. ListTile(
  344. title: Row(
  345. children: [
  346. Image.asset("lib/assets/img/mine_icon_novice.png"),
  347. const SizedBox(
  348. width: 8,
  349. ),
  350. Text("新手指引", style: textStyle),
  351. ],
  352. ),
  353. contentPadding: rowPadding,
  354. trailing: arrowRight5(),
  355. onTap: () {
  356. UmengCommonSdk.onEvent("my_novice", {});
  357. NavigatorUtil.goPage(context, (context) => GuidePage());
  358. },
  359. ),
  360. ],
  361. ).toList(),
  362. ),
  363. ),
  364. Container(
  365. margin: EdgeInsets.only(top: 16.0),
  366. decoration: circular(),
  367. child: ListView(
  368. padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
  369. physics: NeverScrollableScrollPhysics(),
  370. shrinkWrap: true,
  371. children: divideTiles(
  372. context: context,
  373. includeLast: false,
  374. tiles: [
  375. ListTile(
  376. title: Row(
  377. children: [
  378. Image.asset("lib/assets/img/mine_icon_setup.png"),
  379. const SizedBox(
  380. width: 8,
  381. ),
  382. Text("设置", style: textStyle)
  383. ],
  384. ),
  385. contentPadding: rowPadding,
  386. trailing: Row(
  387. children: [
  388. FutureBuilder<RespData<UpdateInfo>>(
  389. builder: (_, data) {
  390. if (data.data?.data?.needUpdate == true) {
  391. return Container(
  392. width: 6,
  393. height: 6,
  394. margin: EdgeInsets.only(right: 8),
  395. decoration: BoxDecoration(shape: BoxShape.circle, color: Color(0xffFF5B1D)),
  396. );
  397. }
  398. return Container();
  399. },
  400. future: checkUpdate(),
  401. ),
  402. arrowRight5()
  403. ],
  404. mainAxisSize: MainAxisSize.min,
  405. ),
  406. onTap: () => NavigatorUtil.go(context, Routes.setting),
  407. ),
  408. ],
  409. ).toList(),
  410. ),
  411. ),
  412. ],
  413. )),
  414. ),
  415. ],
  416. ),
  417. );
  418. }
  419. }