track_page.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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/resource/assets.gen.dart';
  12. import 'package:location/resource/colors.gen.dart';
  13. import 'package:location/resource/string.gen.dart';
  14. import 'package:location/utils/common_expand.dart';
  15. import 'package:location/utils/common_style.dart';
  16. import 'package:location/utils/date_util.dart';
  17. import 'package:sliding_sheet2/sliding_sheet2.dart';
  18. import '../../router/app_pages.dart';
  19. import '../../widget/common_view.dart';
  20. import '../../widget/relative_time_text.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. SizedBox(
  35. width: double.infinity,
  36. height: double.infinity,
  37. child: MapWidget(
  38. controller: controller.mapController,
  39. ),
  40. ),
  41. SafeArea(
  42. child: Container(
  43. margin: EdgeInsets.only(top: 14.w, left: 12.w),
  44. child: GestureDetector(
  45. onTap: controller.back, child: CommonView.getBackBtnView()),
  46. ),
  47. ),
  48. SlidingSheet(
  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: 1,
  56. // Enable snapping. This is true by default.
  57. snap: true,
  58. // Set custom snapping points.
  59. snappings: [SnapSpec.headerFooterSnap, 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. footerBuilder: (context, state) {
  65. return buildOperationBtn();
  66. },
  67. headerBuilder: (context, state) {
  68. return IntrinsicHeight(
  69. child: Column(
  70. children: [
  71. SizedBox(height: 5.w),
  72. Align(
  73. alignment: Alignment.center,
  74. child: Container(
  75. width: 32.w,
  76. height: 3.w,
  77. decoration: BoxDecoration(
  78. color: '#D9D9D9'.color,
  79. borderRadius: BorderRadius.circular(49.w),
  80. ),
  81. ),
  82. ),
  83. SizedBox(height: 25.w),
  84. buildTrackHeaderView(),
  85. ],
  86. ));
  87. },
  88. builder: (context, state) {
  89. return Column(
  90. children: [
  91. SizedBox(
  92. width: double.infinity,
  93. height: 220.w,
  94. child: TabBarView(
  95. controller: controller.tabController,
  96. children: [
  97. buildTrackHistoryContentView(),
  98. buildTrackNowContentView()
  99. ]),
  100. )
  101. ],
  102. );
  103. },
  104. )
  105. ],
  106. );
  107. }
  108. Widget buildOperationBtn() {
  109. return Container(
  110. margin: EdgeInsets.only(bottom: 18.w, top: 9.w),
  111. child: Row(
  112. mainAxisAlignment: MainAxisAlignment.center,
  113. children: [
  114. Obx(() {
  115. return GestureDetector(
  116. onTap: controller.onTraceDetailClick,
  117. child: AnimatedOpacity(
  118. opacity: controller.currentIndex == 0 ? 1 : 0,
  119. duration: Duration(milliseconds: 250),
  120. child: AnimatedContainer(
  121. width: controller.currentIndex == 0 &&
  122. controller.isShowTraceDetailBtn
  123. ? 152.w
  124. : 0.w,
  125. height: 46.w,
  126. decoration: BoxDecoration(
  127. color: '#147B7DFF'.color,
  128. border:
  129. Border.all(color: ColorName.colorPrimary, width: 1.w),
  130. borderRadius: BorderRadius.circular(46.w),
  131. ),
  132. duration: Duration(milliseconds: 250),
  133. child: Center(
  134. child: Text(
  135. maxLines: 1,
  136. StringName.traceDetail,
  137. style: TextStyle(
  138. fontSize: 14.sp, color: ColorName.colorPrimary),
  139. ),
  140. ),
  141. ),
  142. ),
  143. );
  144. }),
  145. Obx(() {
  146. double width = 152.w;
  147. if (controller.currentIndex == 1) {
  148. width = 322.w;
  149. } else if (controller.isShowTraceDetailBtn) {
  150. width = 152.w;
  151. } else {
  152. width = 322.w;
  153. }
  154. return GestureDetector(
  155. onTap: controller.onTrackQueryClick,
  156. child: AnimatedContainer(
  157. margin: EdgeInsets.only(
  158. left: controller.currentIndex == 0 &&
  159. controller.isShowTraceDetailBtn
  160. ? 18.w
  161. : 0),
  162. duration: Duration(milliseconds: 250),
  163. width: width,
  164. height: 46.w,
  165. decoration: getPrimaryBtnDecoration(46.w),
  166. child: Center(
  167. child: Obx(() {
  168. return Text(
  169. controller.currentIndex == 0
  170. ? StringName.trackQueryPath
  171. : StringName.trackNowLocation,
  172. style: TextStyle(fontSize: 14.sp, color: Colors.white),
  173. );
  174. }),
  175. ),
  176. ),
  177. );
  178. })
  179. ],
  180. ),
  181. );
  182. }
  183. Widget buildTrackHeaderView() {
  184. return Row(
  185. children: [
  186. SizedBox(width: 14.w),
  187. Obx(() {
  188. return Image(
  189. image: controller.userInfo?.isMine == true
  190. ? Assets.images.iconDefaultMineAvatar.provider()
  191. : Assets.images.iconDefaultFriendAvatar.provider(),
  192. width: 32.w,
  193. height: 32.w);
  194. }),
  195. SizedBox(width: 10.w),
  196. Expanded(
  197. child: Text(
  198. '${controller.userInfo?.getUserNickName() ?? ''}的轨迹',
  199. style: TextStyle(
  200. overflow: TextOverflow.ellipsis,
  201. fontSize: 16.sp,
  202. color: ColorName.black80,
  203. fontWeight: FontWeight.bold),
  204. ),
  205. ),
  206. buildOperationTabBar(),
  207. SizedBox(width: 12.w),
  208. ],
  209. );
  210. }
  211. Widget buildOperationTabBar() {
  212. return IntrinsicWidth(
  213. child: Container(
  214. padding: EdgeInsets.all(2.w),
  215. decoration: BoxDecoration(
  216. color: '#F3F3F3'.color,
  217. borderRadius: BorderRadius.circular(48.w),
  218. ),
  219. height: 32.w,
  220. child: TabBar(
  221. controller: controller.tabController,
  222. indicator: BoxDecoration(
  223. color: ColorName.colorPrimary,
  224. borderRadius: BorderRadius.circular(48.w),
  225. ),
  226. dividerHeight: 0,
  227. indicatorSize: TabBarIndicatorSize.tab,
  228. unselectedLabelStyle:
  229. TextStyle(fontSize: 14.sp, color: '#666666'.color),
  230. labelStyle: TextStyle(fontSize: 14.sp, color: ColorName.white),
  231. tabs: [
  232. Tab(text: StringName.trackHistory),
  233. Tab(text: StringName.trackNowLocation)
  234. ],
  235. ),
  236. ),
  237. );
  238. }
  239. Widget buildTrackHistoryContentView() {
  240. return Column(
  241. children: [
  242. SizedBox(height: 10.w),
  243. Builder(builder: (context) {
  244. return GestureDetector(
  245. onTap: () {
  246. controller.onTrackStartTimeClick(context);
  247. },
  248. child: Padding(
  249. padding: EdgeInsets.symmetric(vertical: 9.w),
  250. child: Row(
  251. children: [
  252. SizedBox(width: 14.w),
  253. Text(
  254. StringName.trackStartTime,
  255. style: TextStyle(
  256. fontSize: 14.sp,
  257. color: ColorName.black80,
  258. fontWeight: FontWeight.bold),
  259. ),
  260. Spacer(),
  261. Obx(() {
  262. return Text(
  263. controller.trackStartTime?.format('yyyy-MM-dd HH:mm') ??
  264. '',
  265. style:
  266. TextStyle(fontSize: 14.sp, color: ColorName.black50),
  267. );
  268. }),
  269. SizedBox(width: 6.w),
  270. Assets.images.iconTrackSelectTimeArrow
  271. .image(width: 16.w, height: 16.w),
  272. SizedBox(width: 14.w),
  273. ],
  274. ),
  275. ),
  276. );
  277. }),
  278. Builder(builder: (context) {
  279. return GestureDetector(
  280. onTap: () {
  281. controller.onTrackEndTimeClick(context);
  282. },
  283. child: Padding(
  284. padding: EdgeInsets.symmetric(vertical: 9.w),
  285. child: Row(
  286. children: [
  287. SizedBox(width: 14.w),
  288. Text(
  289. StringName.trackEndTime,
  290. style: TextStyle(
  291. fontSize: 14.sp,
  292. color: ColorName.black80,
  293. fontWeight: FontWeight.bold),
  294. ),
  295. Spacer(),
  296. Obx(() {
  297. return Text(
  298. controller.trackEndTime?.format('yyyy-MM-dd HH:mm') ?? '',
  299. style:
  300. TextStyle(fontSize: 14.sp, color: ColorName.black50),
  301. );
  302. }),
  303. SizedBox(width: 6.w),
  304. Assets.images.iconTrackSelectTimeArrow
  305. .image(width: 16.w, height: 16.w),
  306. SizedBox(width: 14.w),
  307. ],
  308. ),
  309. ),
  310. );
  311. }),
  312. SizedBox(height: 12.w),
  313. Obx(() {
  314. return Visibility(
  315. visible: controller.startAddress != null ||
  316. controller.endAddress != null,
  317. child: Container(
  318. padding: EdgeInsets.all(12.w),
  319. margin: EdgeInsets.symmetric(horizontal: 14.w),
  320. width: double.infinity,
  321. decoration: BoxDecoration(
  322. color: '#E5F8F8F8'.color,
  323. borderRadius: BorderRadius.circular(12.w),
  324. ),
  325. child: Column(
  326. children: [
  327. buildAddressInfoView(
  328. '#12C172'.color,
  329. StringName.trackStartLocation,
  330. controller.startAddress ?? ''),
  331. Align(
  332. alignment: Alignment.centerLeft,
  333. child: Container(
  334. margin: EdgeInsets.only(left: 3.5.w),
  335. child: Assets.images.bgTrackLocationTie
  336. .image(width: 1.5.w))),
  337. buildAddressInfoView(
  338. '#F3353A'.color,
  339. StringName.trackEndLocation,
  340. controller.endAddress ?? ''),
  341. ],
  342. )),
  343. );
  344. })
  345. ],
  346. );
  347. }
  348. Widget buildAddressInfoView(Color color, String title, String content) {
  349. return Row(
  350. children: [
  351. Container(
  352. width: 10.w,
  353. height: 10.w,
  354. decoration: BoxDecoration(
  355. shape: BoxShape.circle,
  356. border: Border.all(color: color, width: 2.w),
  357. ),
  358. ),
  359. SizedBox(width: 11.w),
  360. Text(title,
  361. style: TextStyle(
  362. fontSize: 13.sp,
  363. color: ColorName.black80,
  364. fontWeight: FontWeight.bold)),
  365. Expanded(
  366. child: Text(content,
  367. style: TextStyle(fontSize: 13.sp, color: ColorName.black70)),
  368. )
  369. ],
  370. );
  371. }
  372. Widget buildTrackNowContentView() {
  373. return Column(
  374. children: [
  375. SizedBox(height: 20.w),
  376. Row(
  377. children: [
  378. SizedBox(width: 12.w),
  379. Assets.images.iconTrackLocationNow.image(width: 20.w, height: 20.w),
  380. SizedBox(width: 3.w),
  381. Obx(() {
  382. return RelativeTimeText(
  383. startPerchText: '当前位置·',
  384. endPerchText:
  385. controller.currentLocation?.lastUpdateTime == null
  386. ? ''
  387. : '更新',
  388. timestamp: controller.currentLocation?.lastUpdateTime,
  389. updateInterval: Duration(minutes: 1),
  390. style: TextStyle(
  391. fontSize: 15.sp,
  392. color: '#333333'.color,
  393. fontWeight: FontWeight.bold));
  394. })
  395. ],
  396. ),
  397. SizedBox(height: 16.w),
  398. Container(
  399. width: double.infinity,
  400. margin: EdgeInsets.symmetric(horizontal: 12.w),
  401. padding: EdgeInsets.all(14.w),
  402. decoration: BoxDecoration(
  403. color: '#F9F9F9'.color,
  404. borderRadius: BorderRadius.circular(6.w),
  405. ),
  406. child: Obx(() {
  407. return Text(controller.currentLocation?.address ?? '--',
  408. style: TextStyle(fontSize: 14.sp, color: '#666666'.color));
  409. }),
  410. )
  411. ],
  412. );
  413. }
  414. }