track_page.dart 8.1 KB

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