main_page.dart 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_map/flutter_map.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:get/get.dart';
  6. import 'package:location/base/base_page.dart';
  7. import 'package:location/data/bean/user_info.dart';
  8. import 'package:location/module/main/main_controller.dart';
  9. import 'package:location/resource/assets.gen.dart';
  10. import 'package:location/resource/colors.gen.dart';
  11. import 'package:location/resource/string.gen.dart';
  12. import 'package:location/utils/common_expand.dart';
  13. import 'package:sliding_sheet2/sliding_sheet2.dart';
  14. import '../../router/app_pages.dart';
  15. import 'main_friend_item.dart';
  16. class MainPage extends BasePage<MainController> {
  17. const MainPage({super.key});
  18. static start({bool? isNotClear, Map<String, dynamic>? arguments}) {
  19. if (isNotClear == null || !isNotClear) {
  20. Get.offAllNamed(RoutePath.mainTab, arguments: arguments);
  21. } else {
  22. Get.toNamed(RoutePath.mainTab, arguments: arguments);
  23. }
  24. }
  25. @override
  26. bool immersive() {
  27. return true;
  28. }
  29. @override
  30. Widget buildBody(BuildContext context) {
  31. return PopScope(
  32. canPop: false,
  33. onPopInvokedWithResult: (bool didPop, dynamic result) {
  34. controller.onAppBack();
  35. },
  36. child: Stack(
  37. children: [
  38. buildMapView(),
  39. buildMapFunView(),
  40. buildMainBottomView(),
  41. buildFriendListView(),
  42. ],
  43. ),
  44. );
  45. }
  46. Widget buildMapView() {
  47. return Padding(
  48. padding: EdgeInsets.only(bottom: 50.h),
  49. child: SizedBox(
  50. width: double.infinity,
  51. child: MapWidget(
  52. controller: controller.mapController,
  53. onMarkerTap: controller.onMarkerTap,
  54. )),
  55. );
  56. }
  57. Widget buildMainBottomView() {
  58. return SlidingSheet(
  59. color: '#F9F9F9'.color,
  60. elevation: 10,
  61. shadowColor: Colors.black.withOpacity(0.1),
  62. cornerRadius: 18.w,
  63. snapSpec: SnapSpec(
  64. initialSnap: SnapSpec.headerFooterSnap,
  65. // Enable snapping. This is true by default.
  66. snap: true,
  67. // Set custom snapping points.
  68. snappings: [SnapSpec.headerFooterSnap, SnapSpec.expanded],
  69. // Define to what the snappings relate to. In this case,
  70. // the total available space that the sheet can expand to.
  71. positioning: SnapPositioning.relativeToAvailableSpace,
  72. ),
  73. // headerBuilder: (context, state) {
  74. // return Container(
  75. // height: 56,
  76. // width: double.infinity,
  77. // color: Colors.green,
  78. // alignment: Alignment.center,
  79. // child: Text(
  80. // 'This is the header',
  81. // ),
  82. // );
  83. // },
  84. footerBuilder: buildFooterBuilder,
  85. headerBuilder: buildHeaderBuilder,
  86. builder: buildTrackEntranceBuilder,
  87. );
  88. }
  89. Widget buildTrackEntranceBuilder(BuildContext context, SheetState state) {
  90. return Container(
  91. height: 200.w,
  92. width: 1.sw,
  93. );
  94. }
  95. Widget buildFriendListView() {
  96. return SafeArea(
  97. child: Container(
  98. margin: EdgeInsets.only(top: 26.w),
  99. child: Row(
  100. children: [
  101. Expanded(child: buildMainFriendList()),
  102. GestureDetector(
  103. onTap: () {
  104. controller.onAddFriendClick();
  105. },
  106. child: Container(
  107. margin: EdgeInsets.only(right: 16.w, left: 8.w),
  108. child: Assets.images.iconMainAddFriend
  109. .image(width: 60.w, height: 60.w)),
  110. )
  111. ],
  112. ),
  113. ),
  114. );
  115. }
  116. Widget buildMapFunView() {
  117. return Positioned(
  118. right: 0.w,
  119. bottom: 230.w,
  120. child: Column(
  121. children: [
  122. GestureDetector(
  123. onTap: controller.onRefreshFriendLocationClick,
  124. child: Container(
  125. margin: EdgeInsets.only(right: 12.w),
  126. child: Assets.images.iconMainRefreshFriendLocation
  127. .image(width: 42.w, height: 42.w)),
  128. ),
  129. SizedBox(height: 14.w),
  130. GestureDetector(
  131. onTap: controller.onCurrentLocationClick,
  132. child: Container(
  133. margin: EdgeInsets.only(right: 12.w),
  134. child: Assets.images.iconMainRefreshMineLocation
  135. .image(width: 42.w, height: 42.w)),
  136. ),
  137. SizedBox(height: 20.w)
  138. ],
  139. ),
  140. );
  141. }
  142. Container buildTabContainer() {
  143. return Container(
  144. decoration: BoxDecoration(
  145. color: ColorName.white,
  146. borderRadius: BorderRadius.only(
  147. topLeft: Radius.circular(20.w),
  148. topRight: Radius.circular(20.w),
  149. ),
  150. boxShadow: [
  151. BoxShadow(
  152. color: ColorName.black.withOpacity(0.01),
  153. blurRadius: 10,
  154. offset: const Offset(0, -2), // changes position of shadow
  155. ),
  156. ],
  157. ),
  158. padding: EdgeInsets.only(top: 13.w, bottom: 23.w),
  159. child: buildMainFunList());
  160. }
  161. Widget buildMainFunList() {
  162. return Row(
  163. children: [
  164. Expanded(
  165. child: buildFunItem(
  166. Assets.images.iconMainFriendGuard.provider(),
  167. StringName.mainFriendListTab,
  168. () => controller.onFriendClick())),
  169. Expanded(child: Obx(() {
  170. return buildFunItem(Assets.images.iconMainNews.provider(),
  171. StringName.mainNewsTab, () => controller.onNewsClick(),
  172. isShowDot: controller.hasUnreadMessage);
  173. })),
  174. Expanded(
  175. child: buildFunItem(
  176. Assets.images.iconMainHelp.provider(),
  177. StringName.mainHelpTab,
  178. () => controller.onUrgentContactClick())),
  179. Expanded(
  180. child: buildFunItem(Assets.images.iconMainMine.provider(),
  181. StringName.mainMineTab, () => controller.onMineClick()))
  182. ],
  183. );
  184. }
  185. Widget buildFunItem(ImageProvider imgProvider, String title, Function() onTap,
  186. {bool? isShowDot}) {
  187. return GestureDetector(
  188. onTap: onTap,
  189. child: IntrinsicHeight(
  190. child: Column(
  191. children: [
  192. Stack(children: [
  193. SizedBox(
  194. width: 44.w, height: 44.w, child: Image(image: imgProvider)),
  195. Visibility(
  196. visible: isShowDot ?? false,
  197. child: Positioned(
  198. top: 6.w,
  199. right: 6.w,
  200. child: Container(
  201. width: 10.w,
  202. height: 10.w,
  203. decoration: BoxDecoration(
  204. shape: BoxShape.circle,
  205. color: '#FF333D'.color, // 背景颜色
  206. ),
  207. ),
  208. ),
  209. )
  210. ]),
  211. Text(title,
  212. style: TextStyle(
  213. fontSize: 12.sp,
  214. color: ColorName.black70,
  215. fontWeight: FontWeight.bold))
  216. ],
  217. ),
  218. ),
  219. );
  220. }
  221. Widget buildSelectFriendInfoView() {
  222. return Obx(() {
  223. UserInfo? userInfo = controller.selectedFriend;
  224. if (userInfo == null) {
  225. return SizedBox(
  226. height: 86.w,
  227. );
  228. }
  229. return mainSelectedFriendItem(
  230. userInfo,
  231. (controller.memberStatusInfo.value == null ||
  232. controller.memberStatusInfo.value?.expired == true),
  233. viewTraceClick: () => controller.onViewTraceClick(userInfo));
  234. });
  235. }
  236. Widget buildMainFriendList() {
  237. return SizedBox(
  238. height: 58.w,
  239. child: Obx(() {
  240. return ListView(
  241. physics: const BouncingScrollPhysics(
  242. parent: AlwaysScrollableScrollPhysics()),
  243. padding: EdgeInsets.only(left: 12.w),
  244. scrollDirection: Axis.horizontal,
  245. children: [
  246. for (UserInfo userInfo in controller.integrateList)
  247. Obx(() {
  248. return mainFriendItem(
  249. userInfo, controller.selectedFriend?.id == userInfo.id,
  250. onTap: () {
  251. controller.onSelectUserClick(userInfo);
  252. });
  253. })
  254. ],
  255. );
  256. }),
  257. );
  258. }
  259. Widget buildFooterBuilder(BuildContext context, SheetState state) {
  260. return buildTabContainer();
  261. }
  262. Widget buildHeaderBuilder(BuildContext context, SheetState state) {
  263. return IntrinsicHeight(
  264. child: Column(
  265. children: [
  266. SizedBox(height: 5.w),
  267. Container(
  268. width: 32.w,
  269. height: 3.w,
  270. decoration: BoxDecoration(
  271. color: '#D9D9D9'.color,
  272. borderRadius: BorderRadius.all(Radius.circular(49.w))),
  273. ),
  274. SizedBox(height: 12.w),
  275. buildSelectFriendInfoView(),
  276. SizedBox(height: 13.w)
  277. ],
  278. ),
  279. );
  280. }
  281. }