sport_history_share_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import 'dart:math';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. import 'package:sport/bean/game.dart';
  6. import 'package:sport/bean/sport_detail.dart';
  7. import 'package:sport/pages/run/run_share.dart';
  8. import 'package:sport/pages/run/run_share_simple.dart';
  9. import 'package:sport/provider/user_model.dart';
  10. import 'package:sport/utils/strings.dart';
  11. import 'package:sport/widgets/appbar.dart';
  12. import 'package:sport/widgets/image.dart';
  13. import 'package:sport/widgets/misc.dart';
  14. class SportHistorySharePage extends StatefulWidget {
  15. final Map<GameInfoData, RecordsTodaySum> gameRecord;
  16. final bool today;
  17. SportHistorySharePage(this.gameRecord, {this.today = false});
  18. @override
  19. State<StatefulWidget> createState() => _PageState();
  20. }
  21. class _PageState extends State<SportHistorySharePage> {
  22. late List<GlobalKey> keys;
  23. int _index = 0;
  24. @override
  25. void initState() {
  26. keys = List.filled(widget.gameRecord.length, GlobalKey());
  27. super.initState();
  28. }
  29. @override
  30. void dispose() {
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. List<GameInfoData> items = widget.gameRecord.keys.toList();
  36. String date = widget.gameRecord.values.first.getDate(0);
  37. return Scaffold(
  38. body: Stack(
  39. fit: StackFit.expand,
  40. children: [
  41. PageView.builder(
  42. itemCount: items.length,
  43. onPageChanged: (index) {
  44. _index = index;
  45. },
  46. itemBuilder: (context, index) {
  47. GameInfoData game = items[index];
  48. RecordsTodaySum record = widget.gameRecord[game]!;
  49. double duration = record.durationMin;
  50. int consume = record.consume;
  51. int step = record.step;
  52. int crouchCount = record.crouch;
  53. int jumpCount = record.jump;
  54. return SingleChildScrollView(
  55. child: RepaintBoundary(
  56. key: keys[index],
  57. child: Container(
  58. width: double.infinity,
  59. height: MediaQuery.of(context).size.width * 2.165333333333333,
  60. decoration: BoxDecoration(image: DecorationImage(image: CachedNetworkImageProvider(game.shareBg ?? "") , fit: BoxFit.fitHeight), color: Colors.black),
  61. child: Column(
  62. crossAxisAlignment: CrossAxisAlignment.start,
  63. children: [
  64. Padding(
  65. padding: const EdgeInsets.fromLTRB(24.0, 120.0, 0, 0),
  66. child: Column(
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. children: [
  69. Text(
  70. "${game.name}",
  71. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 35.0),
  72. ),
  73. SizedBox(
  74. height: 5,
  75. ),
  76. Text(
  77. "${widget.today ? "今日":"$date"}共运动了${record.times}次",
  78. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 18.0),
  79. ),
  80. SizedBox(
  81. height: 40,
  82. ),
  83. Text(
  84. "总消耗(大卡)",
  85. style: Theme.of(context).textTheme.headline6,
  86. ),
  87. SizedBox(
  88. height: 5,
  89. ),
  90. Text(
  91. "${consume}",
  92. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 35.0, fontFamily: "DIN"),
  93. ),
  94. SizedBox(
  95. height: 40,
  96. ),
  97. Text(
  98. "总时长(分钟)",
  99. style: Theme.of(context).textTheme.headline6,
  100. ),
  101. SizedBox(
  102. height: 5,
  103. ),
  104. Text(
  105. "${toString(max(1.0, duration))}",
  106. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 35.0, fontFamily: "DIN"),
  107. ),
  108. SizedBox(
  109. height: 30,
  110. ),
  111. Container(
  112. height: 120.0,
  113. child: Column(
  114. children: [
  115. Row(
  116. crossAxisAlignment: CrossAxisAlignment.end,
  117. children: [
  118. Text(
  119. "总步数 ",
  120. style: Theme.of(context).textTheme.headline6,
  121. ),
  122. Text(
  123. "${step}",
  124. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 20.0, fontFamily: "DIN"),
  125. strutStyle: fixedLine,
  126. ),
  127. Text(
  128. " 步",
  129. style: Theme.of(context).textTheme.headline6,
  130. ),
  131. ],
  132. ),
  133. if (crouchCount > 0)
  134. Padding(
  135. padding: const EdgeInsets.symmetric(vertical: 4.0),
  136. child: Row(
  137. crossAxisAlignment: CrossAxisAlignment.end,
  138. children: [
  139. Text(
  140. "下蹲频率 ",
  141. style: Theme.of(context).textTheme.headline6,
  142. ),
  143. Text(
  144. "${(crouchCount / duration * 60).toStringAsFixed(1)}",
  145. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 20.0, fontFamily: "DIN"),
  146. strutStyle: fixedLine,
  147. ),
  148. Text(
  149. " 次/分钟",
  150. style: Theme.of(context).textTheme.headline6,
  151. ),
  152. ],
  153. ),
  154. ),
  155. if (jumpCount > 0)
  156. Padding(
  157. padding: const EdgeInsets.symmetric(vertical: 4.0),
  158. child: Row(
  159. crossAxisAlignment: CrossAxisAlignment.end,
  160. children: [
  161. Text(
  162. "跳跃频率 ",
  163. style: Theme.of(context).textTheme.headline6,
  164. ),
  165. Text(
  166. "${(jumpCount / duration * 60).toStringAsFixed(1)}",
  167. style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 20.0, fontFamily: "DIN"),
  168. strutStyle: fixedLine,
  169. ),
  170. Text(
  171. " 次/分钟",
  172. style: Theme.of(context).textTheme.headline6,
  173. ),
  174. ],
  175. ),
  176. ),
  177. ],
  178. ),
  179. ),
  180. Consumer<UserModel>(builder: (_, model, __) {
  181. return Row(children: <Widget>[
  182. Container(
  183. width: 30,
  184. height: 30,
  185. decoration: BoxDecoration(border: Border.all(color: Colors.white, width: 1), borderRadius: BorderRadius.circular(30)),
  186. child: CircleAvatar(
  187. backgroundColor: Colors.black26,
  188. backgroundImage: userAvatarProvider(model.user.avatar),
  189. radius: 15,
  190. )),
  191. SizedBox(
  192. width: 12.0,
  193. ),
  194. Text(model.user.name, style: Theme.of(context).textTheme.headline4),
  195. ]);
  196. }),
  197. SizedBox(
  198. height: 10,
  199. ),
  200. // Text("$date", style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Colors.white)),
  201. Container(
  202. padding: EdgeInsets.all(12),
  203. margin: EdgeInsets.only(top: 20),
  204. decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Color(0xff0C0C0C).withOpacity(.3)),
  205. child: Text("${inspirationalPhrases[Random().nextInt(inspirationalPhrases.length)]}", style: Theme.of(context).textTheme.headline4!.copyWith(height: 1.1),),
  206. ),
  207. ],
  208. ),
  209. ),
  210. // Expanded(child: Container()),
  211. // Container(
  212. // color: Colors.black45,
  213. // width: double.infinity,
  214. // padding: EdgeInsets.all(12.0),
  215. // child: Row(
  216. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  217. // children: [
  218. // CachedNetworkImage(
  219. // imageUrl: "http://static.ouj.com/shoes/share/9b7dc07519f44e8286485154ee29d9c3.png",
  220. // width: 80,
  221. // ),
  222. // Text("趣动", style: Theme.of(context).textTheme.headline4),
  223. // ],
  224. // ),
  225. // )
  226. ],
  227. ),
  228. ),
  229. ),
  230. );
  231. }),
  232. Positioned(
  233. left: 0,
  234. right: 0,
  235. top: 0,
  236. child: SafeArea(
  237. child: Row(
  238. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  239. children: [
  240. buildBackButton(context, white: true),
  241. IconButton(
  242. icon: Image.asset(
  243. "lib/assets/img/bbs_icon_share.png",
  244. color: Colors.white,
  245. ),
  246. onPressed: () => _share()),
  247. ],
  248. )),
  249. ),
  250. ],
  251. ));
  252. }
  253. _share() async {
  254. runShare(context, 0, keys[_index], false, app: true);
  255. }
  256. }