main_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. import 'dart:ui';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.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:location/base/base_page.dart';
  8. import 'package:location/data/bean/user_info.dart';
  9. import 'package:location/module/main/main_controller.dart';
  10. import 'package:location/module/main/view.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:sliding_sheet2/sliding_sheet2.dart';
  16. import '../../data/consts/constants.dart';
  17. import '../../router/app_pages.dart';
  18. import '../../utils/common_style.dart';
  19. import '../../utils/common_util.dart';
  20. import '../../widget/marquee_text.dart';
  21. import '../../widget/relative_time_text.dart';
  22. import 'main_friend_item.dart';
  23. class MainPage extends BasePage<MainController> {
  24. const MainPage({super.key});
  25. static start({bool? isNotClear, Map<String, dynamic>? arguments}) {
  26. if (isNotClear == null || !isNotClear) {
  27. Get.offAllNamed(RoutePath.mainTab, arguments: arguments);
  28. } else {
  29. Get.toNamed(RoutePath.mainTab, arguments: arguments);
  30. }
  31. }
  32. @override
  33. bool immersive() {
  34. return true;
  35. }
  36. @override
  37. Widget buildBody(BuildContext context) {
  38. return PopScope(
  39. canPop: false,
  40. onPopInvokedWithResult: (bool didPop, dynamic result) {
  41. controller.onAppBack();
  42. },
  43. child: Stack(
  44. children: [
  45. buildMapView(),
  46. buildMapFunView(),
  47. buildMainBottomView(),
  48. buildFriendListView(),
  49. ],
  50. ),
  51. );
  52. }
  53. Widget buildMapView() {
  54. return Padding(
  55. padding: EdgeInsets.only(bottom: 50.h),
  56. child: SizedBox(
  57. width: double.infinity,
  58. child: MapWidget(
  59. controller: controller.mapController,
  60. onMarkerTap: controller.onMarkerTap,
  61. )),
  62. );
  63. }
  64. Widget buildMainBottomView() {
  65. return SlidingSheet(
  66. color: '#F9F9F9'.color,
  67. elevation: 10,
  68. shadowColor: Colors.black.withOpacity(0.1),
  69. cornerRadius: 18.w,
  70. snapSpec: SnapSpec(
  71. initialSnap: SnapSpec.headerFooterSnap,
  72. // Enable snapping. This is true by default.
  73. snap: true,
  74. // Set custom snapping points.
  75. snappings: [SnapSpec.headerFooterSnap, SnapSpec.expanded],
  76. // Define to what the snappings relate to. In this case,
  77. // the total available space that the sheet can expand to.
  78. positioning: SnapPositioning.relativeToAvailableSpace,
  79. ),
  80. footerBuilder: buildFooterBuilder,
  81. headerBuilder: buildHeaderBuilder,
  82. builder: buildTrackEntranceBuilder,
  83. );
  84. }
  85. Widget buildTrackEntranceBuilder(BuildContext context, SheetState state) {
  86. return Container(
  87. margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 12.w),
  88. padding: EdgeInsets.only(left: 12.w, right: 12.w, top: 12.w, bottom: 9.w),
  89. decoration: BoxDecoration(
  90. color: Colors.white, borderRadius: BorderRadius.circular(20.r)),
  91. child: AspectRatio(
  92. aspectRatio: 336 / 134,
  93. child: Column(
  94. children: [
  95. Row(
  96. children: [
  97. Text(StringName.todaySimpleTrack,
  98. style: TextStyle(
  99. fontSize: 13.sp,
  100. color: '#333333'.color,
  101. fontWeight: FontWeight.bold)),
  102. Spacer(),
  103. Assets.images.iconMainTrackArrow
  104. .image(width: 10.w, height: 10.w),
  105. ],
  106. ),
  107. SizedBox(height: 7.w),
  108. Expanded(
  109. child: Row(
  110. children: [
  111. Container(
  112. margin: EdgeInsets.only(bottom: 3.w, top: 3.w),
  113. child: AspectRatio(
  114. aspectRatio: 1,
  115. child: Assets.images.imgTrackExample.image(),
  116. ),
  117. ),
  118. SizedBox(width: 10.w),
  119. Column(
  120. mainAxisAlignment: MainAxisAlignment.center,
  121. children: [
  122. SizedBox(height: 6.w),
  123. getMainTrackDot('#15CBA1'.color),
  124. Expanded(
  125. child: Container(
  126. margin: EdgeInsets.symmetric(vertical: 4.w),
  127. width: 1.w,
  128. height: double.infinity,
  129. decoration: BoxDecoration(
  130. color: '#F0F0F0'.color,
  131. borderRadius: BorderRadius.circular(100.r),
  132. ),
  133. ),
  134. ),
  135. getMainTrackDot('#E94949'.color),
  136. SizedBox(height: 6.w),
  137. ],
  138. ),
  139. SizedBox(width: 8.w),
  140. Expanded(
  141. child: Column(
  142. children: [
  143. buildTrackPoint(MainTrackType.startPoint,
  144. '广东省广州市天河区高唐路235号靠近C栋2楼时代E-PARK'),
  145. Spacer(),
  146. buildTrackPoint(
  147. MainTrackType.errorPoint, '广东省广州市海珠区滨江东路驾驶花园C栋601'),
  148. ],
  149. ),
  150. )
  151. ],
  152. ),
  153. ),
  154. ],
  155. ),
  156. ),
  157. );
  158. }
  159. Widget buildFriendListView() {
  160. return SafeArea(
  161. child: Container(
  162. margin: EdgeInsets.only(top: 26.w),
  163. child: Row(
  164. children: [
  165. Expanded(child: buildMainFriendList()),
  166. GestureDetector(
  167. onTap: () {
  168. controller.onAddFriendClick();
  169. },
  170. child: Container(
  171. margin: EdgeInsets.only(right: 16.w, left: 8.w),
  172. child: Assets.images.iconMainAddFriend
  173. .image(width: 60.w, height: 60.w)),
  174. )
  175. ],
  176. ),
  177. ),
  178. );
  179. }
  180. Widget buildMapFunView() {
  181. return Positioned(
  182. right: 0.w,
  183. bottom: 230.w,
  184. child: Column(
  185. children: [
  186. GestureDetector(
  187. onTap: controller.onRefreshFriendLocationClick,
  188. child: Container(
  189. margin: EdgeInsets.only(right: 12.w),
  190. child: Assets.images.iconMainRefreshFriendLocation
  191. .image(width: 42.w, height: 42.w)),
  192. ),
  193. SizedBox(height: 14.w),
  194. GestureDetector(
  195. onTap: controller.onCurrentLocationClick,
  196. child: Container(
  197. margin: EdgeInsets.only(right: 12.w),
  198. child: Assets.images.iconMainRefreshMineLocation
  199. .image(width: 42.w, height: 42.w)),
  200. ),
  201. SizedBox(height: 20.w)
  202. ],
  203. ),
  204. );
  205. }
  206. Container buildTabContainer() {
  207. return Container(
  208. decoration: BoxDecoration(
  209. color: ColorName.white,
  210. borderRadius: BorderRadius.only(
  211. topLeft: Radius.circular(20.w),
  212. topRight: Radius.circular(20.w),
  213. ),
  214. boxShadow: [
  215. BoxShadow(
  216. color: ColorName.black.withOpacity(0.01),
  217. blurRadius: 10,
  218. offset: const Offset(0, -2), // changes position of shadow
  219. ),
  220. ],
  221. ),
  222. padding: EdgeInsets.only(top: 13.w, bottom: 23.w),
  223. child: buildMainFunList());
  224. }
  225. Widget buildMainFunList() {
  226. return Row(
  227. children: [
  228. Expanded(
  229. child: buildFunItem(
  230. Assets.images.iconMainFriendGuard.provider(),
  231. StringName.mainFriendListTab,
  232. () => controller.onFriendClick())),
  233. Expanded(child: Obx(() {
  234. return buildFunItem(Assets.images.iconMainNews.provider(),
  235. StringName.mainNewsTab, () => controller.onNewsClick(),
  236. isShowDot: controller.hasUnreadMessage);
  237. })),
  238. Expanded(
  239. child: buildFunItem(
  240. Assets.images.iconMainHelp.provider(),
  241. StringName.mainHelpTab,
  242. () => controller.onUrgentContactClick())),
  243. Expanded(
  244. child: buildFunItem(Assets.images.iconMainMine.provider(),
  245. StringName.mainMineTab, () => controller.onMineClick()))
  246. ],
  247. );
  248. }
  249. Widget buildFunItem(ImageProvider imgProvider, String title, Function() onTap,
  250. {bool? isShowDot}) {
  251. return GestureDetector(
  252. onTap: onTap,
  253. child: IntrinsicHeight(
  254. child: Column(
  255. children: [
  256. Stack(children: [
  257. SizedBox(
  258. width: 44.w, height: 44.w, child: Image(image: imgProvider)),
  259. Visibility(
  260. visible: isShowDot ?? false,
  261. child: Positioned(
  262. top: 6.w,
  263. right: 6.w,
  264. child: Container(
  265. width: 10.w,
  266. height: 10.w,
  267. decoration: BoxDecoration(
  268. shape: BoxShape.circle,
  269. color: '#FF333D'.color, // 背景颜色
  270. ),
  271. ),
  272. ),
  273. )
  274. ]),
  275. Text(title,
  276. style: TextStyle(
  277. fontSize: 12.sp,
  278. color: ColorName.black70,
  279. fontWeight: FontWeight.bold))
  280. ],
  281. ),
  282. ),
  283. );
  284. }
  285. Widget buildMainFriendList() {
  286. return SizedBox(
  287. height: 58.w,
  288. child: Obx(() {
  289. return ListView(
  290. physics: const BouncingScrollPhysics(
  291. parent: AlwaysScrollableScrollPhysics()),
  292. padding: EdgeInsets.only(left: 12.w),
  293. scrollDirection: Axis.horizontal,
  294. children: [
  295. for (UserInfo userInfo in controller.integrateList)
  296. Obx(() {
  297. return mainFriendItem(
  298. userInfo, controller.selectedFriend?.id == userInfo.id,
  299. onTap: () {
  300. controller.onSelectUserClick(userInfo);
  301. });
  302. })
  303. ],
  304. );
  305. }),
  306. );
  307. }
  308. Widget buildFooterBuilder(BuildContext context, SheetState state) {
  309. return buildTabContainer();
  310. }
  311. Widget buildHeaderBuilder(BuildContext context, SheetState state) {
  312. return IntrinsicHeight(
  313. child: Column(
  314. children: [
  315. SizedBox(height: 5.w),
  316. Container(
  317. width: 32.w,
  318. height: 3.w,
  319. decoration: BoxDecoration(
  320. color: '#D9D9D9'.color,
  321. borderRadius: BorderRadius.all(Radius.circular(49.w))),
  322. ),
  323. SizedBox(height: 12.w),
  324. buildSelectFriendInfoView(),
  325. SizedBox(height: 13.w)
  326. ],
  327. ),
  328. );
  329. }
  330. Widget buildSelectFriendInfoView() {
  331. return Container(
  332. width: 336.w,
  333. height: 86.w,
  334. decoration: BoxDecoration(
  335. color: ColorName.white,
  336. borderRadius: BorderRadius.all(Radius.circular(20.w))),
  337. child: Row(
  338. children: [
  339. SizedBox(width: 7.w),
  340. Obx(() {
  341. return buildCustomAvatarOrDefaultAvatarView(
  342. size: 50.w,
  343. avatar: controller.selectedFriend?.avatar,
  344. isMine: controller.selectedFriend?.isMine == true);
  345. }),
  346. SizedBox(width: 5.w),
  347. Expanded(
  348. child: Container(
  349. margin: EdgeInsets.symmetric(vertical: 15.w),
  350. child: Column(
  351. mainAxisAlignment: MainAxisAlignment.center,
  352. crossAxisAlignment: CrossAxisAlignment.start,
  353. children: [
  354. Row(
  355. children: [
  356. Obx(() {
  357. return Text(
  358. controller.selectedFriend?.getUserNickName() ?? '',
  359. style: TextStyle(
  360. fontWeight: FontWeight.bold,
  361. fontSize: 16.sp,
  362. color: '#202020'.color),
  363. );
  364. }),
  365. SizedBox(width: 7.w),
  366. Obx(() {
  367. return RelativeTimeText(
  368. timestamp: controller.selectedFriend?.lastLocation
  369. .value?.lastUpdateTime,
  370. updateInterval: Duration(minutes: 1),
  371. style: TextStyle(
  372. fontSize: 12.sp, color: '#A7A7A7'.color));
  373. }),
  374. Spacer(),
  375. Obx(() {
  376. return controller.selectedFriend != null
  377. ? GestureDetector(
  378. onTap: () => controller.onViewTraceClick(
  379. controller.selectedFriend!),
  380. child: Container(
  381. margin: EdgeInsets.only(right: 16.w),
  382. decoration: getPrimaryBtnDecoration(32.w),
  383. padding: EdgeInsets.symmetric(
  384. horizontal: 21.w, vertical: 5.w),
  385. child: Text(StringName.locationTrace,
  386. style: TextStyle(
  387. fontSize: 15.sp,
  388. color: Colors.white))),
  389. )
  390. : SizedBox.shrink();
  391. }),
  392. ],
  393. ),
  394. Expanded(
  395. child: Container(
  396. margin: EdgeInsets.only(right: 17.w),
  397. child: Obx(() {
  398. return ImageFiltered(
  399. enabled: controller.selectedFriend?.blockedMe ==
  400. true ||
  401. ((controller.memberStatusInfo.value == null ||
  402. controller.memberStatusInfo.value
  403. ?.expired ==
  404. true) &&
  405. !(controller.selectedFriend?.isMine ==
  406. true)),
  407. imageFilter: ImageFilter.blur(
  408. sigmaX: Constants.blurredX,
  409. sigmaY: Constants.blurredY,
  410. ),
  411. child: controller.selectedFriend?.blockedMe == true ||
  412. ((controller.memberStatusInfo.value == null ||
  413. controller.memberStatusInfo.value?.expired ==
  414. true) &&
  415. !(controller.selectedFriend?.isMine ==
  416. true))
  417. ? Text(addressCheck(controller.selectedFriend?.lastLocation.value?.address),
  418. style: TextStyle(
  419. fontSize: 13.sp,
  420. color: ColorName.black50))
  421. : MarqueeText.marquee(
  422. text: addressCheck(controller.selectedFriend
  423. ?.lastLocation.value?.address),
  424. textStyle: TextStyle(
  425. fontSize: 13.sp,
  426. color: ColorName.black50),
  427. containerWidth: 244.w),
  428. );
  429. }),
  430. ),
  431. )
  432. // Text('广东省广州市天河区XX街街XX街区XX村XX')
  433. ],
  434. ),
  435. ),
  436. )
  437. ],
  438. ));
  439. }
  440. }