track_page.dart 8.1 KB

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