track_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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/resource/assets.gen.dart';
  13. import 'package:location/resource/colors.gen.dart';
  14. import 'package:location/resource/string.gen.dart';
  15. import 'package:location/utils/common_expand.dart';
  16. import 'package:location/utils/common_style.dart';
  17. import 'package:location/utils/date_util.dart';
  18. import 'package:sliding_sheet2/sliding_sheet2.dart';
  19. import '../../router/app_pages.dart';
  20. import '../../utils/fixed_size_tab_indicator.dart';
  21. import '../../widget/common_view.dart';
  22. import '../../widget/relative_time_text.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. SizedBox(
  37. width: double.infinity,
  38. height: double.infinity,
  39. child: MapWidget(
  40. controller: controller.mapController,
  41. ),
  42. ),
  43. buildBackBtnView(),
  44. SlidingSheet(
  45. color: ColorName.white,
  46. controller: controller.sheetController,
  47. elevation: 10,
  48. shadowColor: Colors.black.withOpacity(0.1),
  49. cornerRadius: 18.w,
  50. snapSpec: SnapSpec(
  51. initialSnap: 0.45,
  52. // Enable snapping. This is true by default.
  53. snap: true,
  54. // Set custom snapping points.
  55. snappings: [SnapSpec.headerSnap, 0.45, 1.0],
  56. // Define to what the snappings relate to. In this case,
  57. // the total available space that the sheet can expand to.
  58. positioning: SnapPositioning.relativeToAvailableSpace,
  59. ),
  60. headerBuilder: (context, state) {
  61. return buildSheetHeadView();
  62. },
  63. builder: (context, state) {
  64. return buildSheetContentView();
  65. },
  66. )
  67. ],
  68. );
  69. }
  70. Widget buildBackBtnView() {
  71. return SafeArea(
  72. child: GestureDetector(
  73. onTap: controller.back,
  74. child: Container(
  75. margin: EdgeInsets.only(top: 14.w, left: 12.w),
  76. decoration: BoxDecoration(boxShadow: [
  77. BoxShadow(
  78. color: Colors.black.withOpacity(0.05),
  79. blurRadius: 10.w,
  80. offset: Offset(0, 2.w),
  81. ),
  82. ]),
  83. child: CommonView.getBackBtnView(),
  84. ),
  85. ),
  86. );
  87. }
  88. Widget buildSheetContentView() {
  89. return SizedBox(
  90. height: 0.77.sh,
  91. width: double.infinity,
  92. child: Obx(() {
  93. return DefaultTabController(
  94. length: controller.daysList.length,
  95. child: Column(
  96. children: [
  97. SizedBox(
  98. width: double.infinity,
  99. child: TabBar(
  100. tabAlignment: TabAlignment.start,
  101. isScrollable: true,
  102. dividerHeight: 0,
  103. indicator: FixedSizeTabIndicator(
  104. width: 26.w,
  105. height: 3.w,
  106. radius: 0,
  107. color: ColorName.colorPrimary),
  108. unselectedLabelStyle:
  109. TextStyle(fontSize: 13.sp, color: '#666666'.color),
  110. labelStyle: TextStyle(
  111. fontSize: 13.sp,
  112. color: '#333333'.color,
  113. fontWeight: FontWeight.bold),
  114. tabs: controller.daysList.map((e) {
  115. return Tab(
  116. text: e.day,
  117. );
  118. }).toList(),
  119. ),
  120. ),
  121. Container(
  122. color: '#EEEEEE'.color,
  123. height: 1.w,
  124. width: double.infinity,
  125. ),
  126. Expanded(
  127. child: TabBarView(
  128. children: List.generate(
  129. controller.daysList.length,
  130. (index) => TrackDayDetailView(controller.daysList[index],
  131. isExpand: index == 0)),
  132. )),
  133. ],
  134. ),
  135. );
  136. }),
  137. );
  138. }
  139. Widget buildSheetHeadView() {
  140. return IntrinsicHeight(
  141. child: Column(
  142. children: [
  143. SizedBox(height: 5.w),
  144. Align(
  145. alignment: Alignment.center,
  146. child: Container(
  147. width: 32.w,
  148. height: 3.w,
  149. decoration: BoxDecoration(
  150. color: '#D9D9D9'.color,
  151. borderRadius: BorderRadius.circular(49.w),
  152. ),
  153. ),
  154. ),
  155. SizedBox(height: 25.w),
  156. buildTrackHeaderView(),
  157. SizedBox(height: 20.w),
  158. ],
  159. ));
  160. }
  161. Widget buildTrackHeaderView() {
  162. return Row(
  163. children: [
  164. SizedBox(width: 14.w),
  165. Obx(() {
  166. return buildCustomAvatarOrDefaultAvatarView(
  167. size: 32.w,
  168. avatar: controller.userInfo?.avatar,
  169. isMine: controller.userInfo?.isMine == true);
  170. }),
  171. SizedBox(width: 10.w),
  172. Expanded(
  173. child: Text(
  174. '${controller.userInfo?.getUserNickName() ?? ''}的轨迹',
  175. style: TextStyle(
  176. overflow: TextOverflow.ellipsis,
  177. fontSize: 16.sp,
  178. color: ColorName.black80,
  179. fontWeight: FontWeight.bold),
  180. ),
  181. ),
  182. SizedBox(width: 12.w),
  183. ],
  184. );
  185. }
  186. Widget buildTrackHistoryContentView() {
  187. return Column(
  188. children: [
  189. SizedBox(height: 10.w),
  190. Builder(builder: (context) {
  191. return GestureDetector(
  192. onTap: () {
  193. controller.onTrackStartTimeClick(context);
  194. },
  195. child: Padding(
  196. padding: EdgeInsets.symmetric(vertical: 9.w),
  197. child: Row(
  198. children: [
  199. SizedBox(width: 14.w),
  200. Text(
  201. StringName.trackStartTime,
  202. style: TextStyle(
  203. fontSize: 14.sp,
  204. color: ColorName.black80,
  205. fontWeight: FontWeight.bold),
  206. ),
  207. Spacer(),
  208. Obx(() {
  209. return Text(
  210. controller.trackStartTime?.format('yyyy-MM-dd HH:mm') ??
  211. '',
  212. style:
  213. TextStyle(fontSize: 14.sp, color: ColorName.black50),
  214. );
  215. }),
  216. SizedBox(width: 6.w),
  217. Assets.images.iconTrackSelectTimeArrow
  218. .image(width: 16.w, height: 16.w),
  219. SizedBox(width: 14.w),
  220. ],
  221. ),
  222. ),
  223. );
  224. }),
  225. Builder(builder: (context) {
  226. return GestureDetector(
  227. onTap: () {
  228. controller.onTrackEndTimeClick(context);
  229. },
  230. child: Padding(
  231. padding: EdgeInsets.symmetric(vertical: 9.w),
  232. child: Row(
  233. children: [
  234. SizedBox(width: 14.w),
  235. Text(
  236. StringName.trackEndTime,
  237. style: TextStyle(
  238. fontSize: 14.sp,
  239. color: ColorName.black80,
  240. fontWeight: FontWeight.bold),
  241. ),
  242. Spacer(),
  243. Obx(() {
  244. return Text(
  245. controller.trackEndTime?.format('yyyy-MM-dd HH:mm') ?? '',
  246. style:
  247. TextStyle(fontSize: 14.sp, color: ColorName.black50),
  248. );
  249. }),
  250. SizedBox(width: 6.w),
  251. Assets.images.iconTrackSelectTimeArrow
  252. .image(width: 16.w, height: 16.w),
  253. SizedBox(width: 14.w),
  254. ],
  255. ),
  256. ),
  257. );
  258. }),
  259. SizedBox(height: 12.w),
  260. Obx(() {
  261. return Visibility(
  262. visible: controller.startAddress != null ||
  263. controller.endAddress != null,
  264. child: Container(
  265. padding: EdgeInsets.all(12.w),
  266. margin: EdgeInsets.symmetric(horizontal: 14.w),
  267. width: double.infinity,
  268. decoration: BoxDecoration(
  269. color: '#E5F8F8F8'.color,
  270. borderRadius: BorderRadius.circular(12.w),
  271. ),
  272. child: Column(
  273. children: [
  274. buildAddressInfoView(
  275. '#12C172'.color,
  276. StringName.trackStartLocation,
  277. controller.startAddress ?? ''),
  278. Align(
  279. alignment: Alignment.centerLeft,
  280. child: Container(
  281. margin: EdgeInsets.only(left: 3.5.w),
  282. child: Assets.images.bgTrackLocationTie
  283. .image(width: 1.5.w))),
  284. buildAddressInfoView(
  285. '#F3353A'.color,
  286. StringName.trackEndLocation,
  287. controller.endAddress ?? ''),
  288. ],
  289. )),
  290. );
  291. })
  292. ],
  293. );
  294. }
  295. Widget buildAddressInfoView(Color color, String title, String content) {
  296. return Row(
  297. children: [
  298. Container(
  299. width: 10.w,
  300. height: 10.w,
  301. decoration: BoxDecoration(
  302. shape: BoxShape.circle,
  303. border: Border.all(color: color, width: 2.w),
  304. ),
  305. ),
  306. SizedBox(width: 11.w),
  307. Text(title,
  308. style: TextStyle(
  309. fontSize: 13.sp,
  310. color: ColorName.black80,
  311. fontWeight: FontWeight.bold)),
  312. Expanded(
  313. child: Text(content,
  314. style: TextStyle(fontSize: 13.sp, color: ColorName.black70)),
  315. )
  316. ],
  317. );
  318. }
  319. Widget buildTrackNowContentView() {
  320. return Column(
  321. children: [
  322. SizedBox(height: 20.w),
  323. Row(
  324. children: [
  325. SizedBox(width: 12.w),
  326. Assets.images.iconTrackLocationNow.image(width: 20.w, height: 20.w),
  327. SizedBox(width: 3.w),
  328. Obx(() {
  329. return RelativeTimeText(
  330. startPerchText: '当前位置·',
  331. endPerchText:
  332. controller.currentLocation?.lastUpdateTime == null
  333. ? ''
  334. : '更新',
  335. timestamp: controller.currentLocation?.lastUpdateTime,
  336. updateInterval: Duration(minutes: 1),
  337. style: TextStyle(
  338. fontSize: 15.sp,
  339. color: '#333333'.color,
  340. fontWeight: FontWeight.bold));
  341. })
  342. ],
  343. ),
  344. SizedBox(height: 16.w),
  345. Container(
  346. width: double.infinity,
  347. margin: EdgeInsets.symmetric(horizontal: 12.w),
  348. padding: EdgeInsets.all(14.w),
  349. decoration: BoxDecoration(
  350. color: '#F9F9F9'.color,
  351. borderRadius: BorderRadius.circular(6.w),
  352. ),
  353. child: Obx(() {
  354. return Text(controller.currentLocation?.address ?? '--',
  355. style: TextStyle(fontSize: 14.sp, color: '#666666'.color));
  356. }),
  357. )
  358. ],
  359. );
  360. }
  361. }