track_page.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/src/widgets/framework.dart';
  5. import 'package:flutter_map/flutter_map.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import 'package:get/get_core/src/get_main.dart';
  9. import 'package:location/base/base_page.dart';
  10. import 'package:location/data/bean/user_info.dart';
  11. import 'package:location/module/track/track_controller.dart';
  12. import 'package:location/module/track/track_day_detail/track_day_detail_view.dart';
  13. import 'package:location/module/track/track_day_detail/track_share_view.dart';
  14. import 'package:location/resource/colors.gen.dart';
  15. import 'package:location/utils/common_expand.dart';
  16. import 'package:location/utils/common_style.dart';
  17. import 'package:sliding_sheet2/sliding_sheet2.dart';
  18. import '../../resource/assets.gen.dart';
  19. import '../../resource/string.gen.dart';
  20. import '../../router/app_pages.dart';
  21. import '../../utils/fixed_size_tab_indicator.dart';
  22. import '../../widget/common_view.dart';
  23. class TrackPage extends BasePage<TrackController> {
  24. const TrackPage({super.key});
  25. static void start(UserInfo userInfo) {
  26. Get.toNamed(RoutePath.track, arguments: userInfo);
  27. }
  28. @override
  29. bool immersive() {
  30. return true;
  31. }
  32. @override
  33. Widget buildBody(BuildContext context) {
  34. return Stack(
  35. children: [
  36. _buildHideShareView(),
  37. SizedBox(
  38. width: double.infinity,
  39. height: double.infinity,
  40. child: MapWidget(
  41. controller: controller.mapController,
  42. ),
  43. ),
  44. buildBackBtnView(),
  45. buildMapFunView(),
  46. SlidingSheet(
  47. listener: (SheetState state) {
  48. controller.setSheetProgress(state.progress);
  49. },
  50. color: ColorName.white,
  51. controller: controller.sheetController,
  52. elevation: 10,
  53. shadowColor: Colors.black.withOpacity(0.1),
  54. cornerRadius: 18.w,
  55. snapSpec: SnapSpec(
  56. initialSnap: 0.45,
  57. // Enable snapping. This is true by default.
  58. snap: true,
  59. // Set custom snapping points.
  60. snappings: [SnapSpec.headerSnap, 0.45, 1.0],
  61. // Define to what the snappings relate to. In this case,
  62. // the total available space that the sheet can expand to.
  63. positioning: SnapPositioning.relativeToAvailableSpace,
  64. ),
  65. headerBuilder: (context, state) {
  66. return buildSheetHeadView();
  67. },
  68. builder: (context, state) {
  69. return buildSheetContentView();
  70. },
  71. ),
  72. Visibility(
  73. visible: Platform.isAndroid,
  74. child: SafeArea(
  75. child: Container(
  76. width: double.infinity,
  77. padding: EdgeInsets.only(right: 12.w),
  78. child: Column(
  79. crossAxisAlignment: CrossAxisAlignment.end,
  80. children: [
  81. Assets.images.iconAmapLogo.image(height: 24.w),
  82. Container(
  83. padding: EdgeInsets.all(1.w),
  84. color: ColorName.white30,
  85. child: Text(StringName.locationCo,
  86. style: TextStyle(
  87. fontSize: 11.sp, color: ColorName.black40)),
  88. )
  89. ],
  90. ),
  91. ),
  92. ),
  93. ),
  94. ],
  95. );
  96. }
  97. Widget _buildHideShareView() {
  98. return RepaintBoundary(
  99. key: controller.shareGlobalKey,
  100. child: Obx(() {
  101. final day = controller.currentTrackDay.value;
  102. final userInfo = controller.userInfo;
  103. final shareTrackData = controller.shareTrackData;
  104. if (shareTrackData != null && day != null && userInfo != null) {
  105. return TrackShareView(day.start, userInfo, shareTrackData);
  106. }
  107. return SizedBox.shrink();
  108. }),
  109. );
  110. }
  111. Widget buildMapFunView() {
  112. return Obx(() {
  113. return Positioned(
  114. right: 0.w,
  115. bottom: 110.w + controller.sheetProgress * 0.77.sh,
  116. child: Column(
  117. children: [
  118. GestureDetector(
  119. onTap: controller.onCurrentLocationClick,
  120. child: Container(
  121. margin: EdgeInsets.only(right: 12.w),
  122. child: Opacity(
  123. opacity: controller.sheetProgress < 0.6
  124. ? 1.0
  125. : 1.0 -
  126. ((controller.sheetProgress - 0.6) / 0.4)
  127. .clamp(0.0, 1.0),
  128. child: Assets.images.iconMainRefreshMineLocation
  129. .image(width: 42.w, height: 42.w),
  130. )),
  131. ),
  132. ],
  133. ),
  134. );
  135. });
  136. }
  137. Widget buildBackBtnView() {
  138. return SafeArea(
  139. child: GestureDetector(
  140. onTap: controller.back,
  141. child: Container(
  142. margin: EdgeInsets.only(top: 14.w, left: 12.w),
  143. decoration: BoxDecoration(boxShadow: [
  144. BoxShadow(
  145. color: Colors.black.withOpacity(0.05),
  146. blurRadius: 10.w,
  147. offset: Offset(0, 2.w),
  148. ),
  149. ]),
  150. child: CommonView.getBackBtnView(),
  151. ),
  152. ),
  153. );
  154. }
  155. Widget buildSheetContentView() {
  156. return SizedBox(
  157. height: 0.77.sh,
  158. width: double.infinity,
  159. child: Obx(() {
  160. return Visibility(
  161. visible: controller.tabController != null,
  162. child: Column(
  163. children: [
  164. SizedBox(
  165. width: double.infinity,
  166. child: TabBar(
  167. controller: controller.tabController,
  168. tabAlignment: TabAlignment.start,
  169. isScrollable: true,
  170. dividerHeight: 0,
  171. indicator: FixedSizeTabIndicator(
  172. width: 26.w,
  173. height: 3.w,
  174. radius: 0,
  175. color: ColorName.colorPrimary),
  176. unselectedLabelStyle:
  177. TextStyle(fontSize: 13.sp, color: '#666666'.color),
  178. labelStyle: TextStyle(
  179. fontSize: 13.sp,
  180. color: '#333333'.color,
  181. fontWeight: FontWeight.bold),
  182. tabs: controller.daysList.map((e) {
  183. return Tab(
  184. text: e.day,
  185. );
  186. }).toList(),
  187. ),
  188. ),
  189. Container(
  190. color: '#EEEEEE'.color,
  191. height: 1.w,
  192. width: double.infinity,
  193. ),
  194. Expanded(
  195. child: TabBarView(
  196. controller: controller.tabController,
  197. children: List.generate(
  198. controller.daysList.length,
  199. (index) => TrackDayDetailView(controller.daysList[index],
  200. isExpand: index == 0)),
  201. )),
  202. ],
  203. ),
  204. );
  205. }),
  206. );
  207. }
  208. Widget buildSheetHeadView() {
  209. return IntrinsicHeight(
  210. child: Column(
  211. children: [
  212. SizedBox(height: 5.w),
  213. Align(
  214. alignment: Alignment.center,
  215. child: Container(
  216. width: 32.w,
  217. height: 3.w,
  218. decoration: BoxDecoration(
  219. color: '#D9D9D9'.color,
  220. borderRadius: BorderRadius.circular(49.w),
  221. ),
  222. ),
  223. ),
  224. SizedBox(height: 25.w),
  225. buildTrackHeaderView(),
  226. SizedBox(height: 20.w),
  227. ],
  228. ));
  229. }
  230. Widget buildTrackHeaderView() {
  231. return Row(
  232. children: [
  233. SizedBox(width: 14.w),
  234. Obx(() {
  235. return buildCustomAvatarOrDefaultAvatarView(
  236. size: 32.w,
  237. avatar: controller.userInfo?.avatar,
  238. isMine: controller.userInfo?.isMine == true);
  239. }),
  240. SizedBox(width: 10.w),
  241. Expanded(
  242. child: Text(
  243. '${controller.userInfo?.getUserNickName() ?? ''}的轨迹',
  244. style: TextStyle(
  245. overflow: TextOverflow.ellipsis,
  246. fontSize: 16.sp,
  247. color: ColorName.black80,
  248. fontWeight: FontWeight.bold),
  249. ),
  250. ),
  251. SizedBox(width: 12.w),
  252. ],
  253. );
  254. }
  255. }