my_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_blue/flutter_blue.dart';
  5. import 'package:provider/provider.dart';
  6. import 'package:qr_flutter/qr_flutter.dart';
  7. import 'package:sport/bean/post_user.dart';
  8. import 'package:sport/pages/social/user_friend_add_page.dart';
  9. import 'package:sport/provider/bluetooth.dart';
  10. import 'package:sport/provider/user_model.dart';
  11. import 'package:sport/router/navigator_util.dart';
  12. import 'package:sport/router/routes.dart';
  13. import 'package:sport/services/api/inject_api.dart';
  14. import 'package:sport/utils/toast.dart';
  15. import 'package:sport/widgets/image.dart';
  16. import 'package:sport/widgets/list_tile.dart';
  17. import 'package:sport/widgets/space.dart';
  18. import 'package:sport/widgets/dialog/search_device.dart';
  19. class MyPage extends StatefulWidget {
  20. @override
  21. _MyPageState createState() => _MyPageState();
  22. }
  23. class _MyPageState extends State<MyPage> with InjectApi {
  24. @override
  25. void initState() {
  26. super.initState();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return AnnotatedRegion<SystemUiOverlayStyle>(
  31. value: SystemUiOverlayStyle.dark,
  32. child: Material(
  33. child: Scaffold(
  34. backgroundColor: Colors.white,
  35. body: SafeArea(
  36. child: Column(
  37. children: <Widget>[
  38. // 放外面一点的吧
  39. // InkWell(
  40. // onTap: () => NavigatorUtil.go(context, Routes.userInfo),
  41. // child:
  42. // AspectRatio(
  43. // aspectRatio: 1125 / 435.0,
  44. // child: Container(
  45. // alignment: Alignment.bottomCenter,
  46. // padding: EdgeInsets.fromLTRB(24.0, 0, 24.0, 34.0),
  47. // decoration: new BoxDecoration(
  48. //// image: new DecorationImage(
  49. //// image: new AssetImage("lib/assets/img/bg_userprofile.jpg"),
  50. //// ),
  51. // ),
  52. // ),
  53. // ),
  54. // ),
  55. Space(height: 37.0,),
  56. Container(
  57. padding: EdgeInsets.only(top: 12.0),
  58. transform: Matrix4.translationValues(0, -10, 0),
  59. decoration: BoxDecoration(borderRadius: BorderRadius.vertical(top: Radius.circular(10)), color: Colors.white),
  60. child: ListView(
  61. padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
  62. physics: NeverScrollableScrollPhysics(),
  63. shrinkWrap: true,
  64. children: divideTiles(
  65. context: context,
  66. includeLast: true,
  67. tiles: [
  68. ListTile(
  69. contentPadding: EdgeInsets.only(bottom: 20, top: 5),
  70. title: Consumer<UserModel>(
  71. builder: (_, model, __) => model.user == null
  72. ? Container()
  73. : Row(
  74. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  75. children: <Widget>[
  76. Row(
  77. children: <Widget>[
  78. CircleAvatar(
  79. backgroundImage: userAvatarProvider(model.user.avatar),
  80. radius: 30,
  81. ),
  82. Space(
  83. width: 12,
  84. ),
  85. Column(
  86. mainAxisSize: MainAxisSize.min,
  87. mainAxisAlignment: MainAxisAlignment.center,
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: <Widget>[
  90. Text(model.user.name ?? "", style: TextStyle(color: Color(0xff333333), fontSize: 18,fontWeight: FontWeight.w600)),
  91. Space(
  92. height: 7,
  93. ),
  94. Row(
  95. children: <Widget>[
  96. Row(
  97. children: <Widget>[
  98. Image.asset("lib/assets/img/mine_icon_${model.user.gender == 1 ? "man" : "girl"}_gray.png"),
  99. Space(
  100. width: 4,
  101. ),
  102. Text(
  103. model.user.gender == 1 ? "男" : "女",
  104. style: TextStyle(color: Color(0xff999999), fontSize: 12),
  105. ),
  106. ],
  107. ),
  108. if ((model.user.age ?? 0) != 0)
  109. Padding(
  110. padding: const EdgeInsets.only(left: 10.0),
  111. child: Text(
  112. "${model.user.age}岁",
  113. style: TextStyle(color: Color(0xff999999), fontSize: 12),
  114. ),
  115. ),
  116. if (model.user.city != null)
  117. Padding(
  118. padding: const EdgeInsets.only(left: 10.0),
  119. child: Text(
  120. "${model.user.province}${model.user.province == model.user.city ? '' : model.user.city}",
  121. style: TextStyle(color: Colors.white, fontSize: 12),
  122. ),
  123. ),
  124. ],
  125. ),
  126. ],
  127. ),
  128. ],
  129. ),
  130. Row(
  131. children: <Widget>[
  132. Container(
  133. width: 22.0,
  134. height: 22.0,
  135. child: Image.asset("lib/assets/img/mine_icon_code.png"),
  136. ),
  137. Space(
  138. width: 17.0,
  139. ),
  140. arrowRight5(),
  141. ],
  142. )
  143. ,],
  144. )
  145. ),
  146. onTap:() => NavigatorUtil.go(context, Routes.userInfo),
  147. ),
  148. Selector<Bluetooth, BluetoothDevice>(
  149. selector: (_, bluetooth) => bluetooth.device,
  150. builder: (_, device, ___) {
  151. return device == null
  152. ? ListTile(
  153. title: Row(
  154. mainAxisAlignment:MainAxisAlignment.spaceBetween,
  155. children: <Widget>[
  156. Text("暂无连接设备",style: TextStyle(color: Color(0xff999999),fontSize: 16),),
  157. Text("前往连接",style: TextStyle(color: Color(0xff999999),fontSize: 14),)
  158. ],
  159. ),
  160. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  161. trailing: arrowRight5(),
  162. onTap: () => showDialog(context: context, child: SearchDeviceDialog())
  163. )
  164. : ListTile(
  165. leading: Padding(padding: EdgeInsets.only(bottom: 10, top: 5), child: Image.asset("lib/assets/img/mine_image_shoe.png")),
  166. title: Padding(
  167. padding: EdgeInsets.fromLTRB(0, 0, 12.0, 10),
  168. child:
  169. ValueListenableBuilder(
  170. valueListenable: Provider.of<Bluetooth>(context, listen: false).electricityNotifier,
  171. builder: (_, data, ___) => Column(
  172. crossAxisAlignment: CrossAxisAlignment.start,
  173. children: <Widget>[
  174. Text(
  175. "剩余电量 $data%",
  176. style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 12),
  177. ),
  178. Space(
  179. height: 8,
  180. ),
  181. ClipRRect(
  182. borderRadius: BorderRadius.circular(10),
  183. child: Container(
  184. child: LinearProgressIndicator(
  185. value: data / 100,
  186. valueColor: AlwaysStoppedAnimation(Color.fromRGBO(0, 220, 66, 1)
  187. // Color(0xffFF5B1D)
  188. ),
  189. ),
  190. height: 7,
  191. ),
  192. )
  193. ],
  194. ))),
  195. trailing: arrowRight5(),
  196. contentPadding: EdgeInsets.symmetric(horizontal: 0.0,vertical: 10.0),
  197. onTap: () {
  198. var device = Provider.of<Bluetooth>(context, listen: false).device;
  199. if (device == null) {
  200. ToastUtil.show("没连接设备!");
  201. return;
  202. }
  203. NavigatorUtil.go(context, Routes.deviceInfo);
  204. },
  205. );
  206. },
  207. ),
  208. // ListTile(
  209. // title: Text("运动详情",style: TextStyle(fontSize: 16),),
  210. // contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  211. // trailing: arrowRight5(),
  212. // onTap: () => NavigatorUtil.go(context, Routes.sportDetail),
  213. // ),
  214. ListTile(
  215. title: Text("我的等级",style: TextStyle(fontSize: 16),),
  216. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  217. trailing: arrowRight5(),
  218. onTap: () => NavigatorUtil.go(context, Routes.level),
  219. ),
  220. ListTile(
  221. title: Text("我的运动",style: TextStyle(fontSize: 16)),
  222. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  223. trailing: arrowRight5(),
  224. onTap: () => NavigatorUtil.go(context, Routes.gamelistpage),
  225. ),
  226. ListTile(
  227. title: Text("我的帖子",style: TextStyle(fontSize: 16)),
  228. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  229. trailing: arrowRight5(),
  230. onTap: () {
  231. var userModel = Provider.of<UserModel>(context, listen: false);
  232. var user = userModel.user;
  233. NavigatorUtil.goSocialUserDetail(context, PostUser(id: "${user.id}", name: user.name, avatar: user.avatar));
  234. },
  235. ),
  236. ListTile(
  237. title: Text("用户反馈",style: TextStyle(fontSize: 16)),
  238. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  239. trailing: arrowRight5(),
  240. onTap: () => NavigatorUtil.go(context, Routes.feedback),
  241. ),
  242. ListTile(
  243. title: Text("设置",style: TextStyle(fontSize: 16)),
  244. contentPadding: EdgeInsets.symmetric(horizontal: 0.0),
  245. trailing: arrowRight5(),
  246. onTap: () => NavigatorUtil.go(context, Routes.setting),
  247. ),
  248. ],
  249. ).toList(),
  250. )),
  251. ],
  252. ),
  253. ),
  254. ),
  255. ),
  256. );
  257. }
  258. }