run_finish.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_timeline/flutter_timeline.dart';
  3. import 'package:flutter_timeline/indicator_position.dart';
  4. import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
  5. import 'package:sport/bean/jog/sum.dart';
  6. import 'package:sport/pages/run/run_detail_page.dart';
  7. import 'package:sport/pages/run/run_page.dart';
  8. import 'package:sport/router/navigator_util.dart';
  9. import 'package:sport/services/api/inject_api.dart';
  10. import 'package:sport/services/api/resp.dart';
  11. import 'package:sport/services/app_lifecycle_state.dart';
  12. import 'package:sport/utils/DateFormat.dart';
  13. import 'package:sport/utils/sport_utils.dart';
  14. import 'package:sport/widgets/appbar.dart';
  15. import 'package:sport/widgets/button_primary.dart';
  16. import 'package:sport/widgets/decoration.dart';
  17. import 'package:sport/widgets/error.dart';
  18. import 'package:sport/widgets/image.dart';
  19. import 'package:sport/widgets/loading.dart';
  20. class RunFinishPage extends StatefulWidget {
  21. final List<Map<String, num>> items;
  22. final int type;
  23. const RunFinishPage({Key? key, required this.items, required this.type}) : super(key: key);
  24. @override
  25. State<StatefulWidget> createState() => _PageState();
  26. }
  27. class _PageState extends LifecycleState<RunFinishPage> {
  28. int _index = 0;
  29. @override
  30. void initState() {
  31. super.initState();
  32. }
  33. @override
  34. void dispose() {
  35. super.dispose();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Padding(
  40. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20.0),
  41. child: Column(
  42. mainAxisSize: MainAxisSize.min,
  43. children: [
  44. ListView.separated(
  45. shrinkWrap: true,
  46. itemBuilder: (BuildContext context, int index) {
  47. var map = widget.items[index];
  48. bool type = widget.type == 2;
  49. String label = index ==0?"目标":"实际";
  50. return GestureDetector(
  51. onTap: () {
  52. setState(() {
  53. _index = index;
  54. });
  55. },
  56. behavior: HitTestBehavior.opaque,
  57. child: Container(
  58. decoration: _index == index ? BoxDecoration(color: Theme.of(context).accentColor.withOpacity(0.06)) : null,
  59. child: Row(
  60. children: [
  61. Expanded(
  62. child: Padding(
  63. padding: const EdgeInsets.all(12.0),
  64. child: Column(
  65. children: [
  66. Text(
  67. type ? "以$label距离 (${formatNum((map["distance"] ?? 0) / 1000, 2)}公里) 保存" : "以$label时间 (${(map["duration"] ?? 0).toInt() ~/ 60}分钟) 保存",
  68. style: Theme.of(context).textTheme.headline1!,
  69. ),
  70. const SizedBox(
  71. height: 8.0,
  72. ),
  73. Row(
  74. children: [
  75. Text("时长 ${DateFormat.toTime((map["duration"] ?? 0).toInt())}", style: Theme.of(context).textTheme.bodyText1!),
  76. const SizedBox(
  77. width: 16.0,
  78. ),
  79. Text("配速 ${SportUtils.pace4((map["duration"] ?? 0).toInt(), ((map["distance"] ?? 0)).toInt())}", style: Theme.of(context).textTheme.bodyText1!),
  80. ],
  81. )
  82. ],
  83. crossAxisAlignment: CrossAxisAlignment.start,
  84. ),
  85. ),
  86. ),
  87. Padding(
  88. padding: const EdgeInsets.all(8.0),
  89. child: Image.asset("lib/assets/img/${_index == index ? "pop_icon_conneted" : "pop_icon_choose_normal"}.png"),
  90. )
  91. ],
  92. ),
  93. ),
  94. );
  95. },
  96. separatorBuilder: (BuildContext context, int index) {
  97. return Divider(height: 1,);
  98. },
  99. itemCount: widget.items.length,
  100. ),
  101. const SizedBox(
  102. height: 16.0,
  103. ),
  104. PrimaryButton(
  105. callback: () {
  106. Navigator.pop(context, _index);
  107. },
  108. content: "确定",
  109. height: 35,
  110. )
  111. ],
  112. ),
  113. );
  114. }
  115. }