map_list_view.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../../model.dart';
  4. import '../../generated/assets.dart';
  5. import '../../route.dart';
  6. import '../../screen.dart';
  7. import '../../service/app.dart';
  8. import '../../service/mock.dart';
  9. import '../../widget/app_dialog.dart';
  10. import '../../widget/app_net_image.dart';
  11. import '../../widget/hard_level.dart';
  12. import '../../widget/page_frame.dart';
  13. import '../mapto/map_to_view.dart';
  14. import 'map_list_controller.dart';
  15. import 'package:common_pub/prelude.dart';
  16. class MapListView extends GetView<MapListController> {
  17. const MapListView({super.key});
  18. static Bindings bindings() {
  19. return BindingsBuilder(() {
  20. Get.lazyPut<PageTopController>(() => PageTopController());
  21. Get.lazyPut<MapListController>(() => MapListController());
  22. });
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. // final PageTopController c = Get.find();
  27. return PageFrame(child: _wBody(context));
  28. }
  29. Widget _wBody(BuildContext context) {
  30. return Obx(() {
  31. final data = controller.mapList;
  32. return Container(
  33. margin: const EdgeInsets.symmetric(horizontal: 18, vertical: 18),
  34. width: context.width,
  35. height: context.height,
  36. decoration: const BoxDecoration(
  37. color: Colors.white,
  38. borderRadius: BorderRadius.all(Radius.circular(12.0)),
  39. // border: Border.all(width: 1, color: Colors.red),
  40. ),
  41. child: Column(children: [
  42. Padding(
  43. padding: const EdgeInsets.only(left: 30, top: 15),
  44. child: Row(
  45. children: [
  46. const Icon(
  47. Icons.circle,
  48. size: 16,
  49. color: Color(0xff1a82c0),
  50. ),
  51. const SizedBox(width: 6),
  52. Text(
  53. '地图列表 ( ${data.length} )',
  54. style: const TextStyle(
  55. color: Colors.black,
  56. fontSize: 15,
  57. fontWeight: FontWeight.w500,
  58. ),
  59. textAlign: TextAlign.start,
  60. maxLines: 1,
  61. overflow: TextOverflow.ellipsis,
  62. ),
  63. ],
  64. ),
  65. ),
  66. Expanded(
  67. child: Row(
  68. children: [
  69. // Container(
  70. // margin: const EdgeInsets.symmetric(horizontal: 18, vertical: 18),
  71. // width: 1.68.wp,
  72. // // child: Image.asset(Assets.imagesIcArrowLeft),
  73. // ),
  74. Expanded(
  75. child: Container(
  76. // color: Colors.blue,
  77. margin: const EdgeInsets.only(
  78. left: 30, right: 30, top: 10, bottom: 20),
  79. child: _dataView(
  80. context, data, controller.mapInfoListScrollController),
  81. )),
  82. // Container(
  83. // margin: const EdgeInsets.symmetric(horizontal: 18, vertical: 18),
  84. // width: 1.68.wp,
  85. // // child: Image.asset(Assets.imagesIcArrowRight),
  86. // ),
  87. ],
  88. ),
  89. )
  90. ]));
  91. });
  92. }
  93. Widget _dataView(BuildContext context, List<MapInfo> data,
  94. ScrollController scrollController) {
  95. return GridView.builder(
  96. padding: const EdgeInsets.all(0.0),
  97. itemCount: data.length,
  98. controller: scrollController,
  99. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  100. //设置列数
  101. crossAxisCount: 5,
  102. //设置横向间距
  103. crossAxisSpacing: 30,
  104. //设置主轴间距
  105. mainAxisSpacing: 30,
  106. //设置宽高比例
  107. childAspectRatio: 0.71),
  108. itemBuilder: (context, i) {
  109. return GalleryCardWidget(data: data[i]);
  110. });
  111. }
  112. }
  113. class GalleryCardWidget extends GetView<MapListController> {
  114. final MapInfo data;
  115. const GalleryCardWidget({super.key, required this.data});
  116. void onTap() async {
  117. var pin = '';
  118. var isCancel = false;
  119. if (data.needPin) {
  120. isCancel = true;
  121. await Get.dialog(AppDialog(
  122. title: const Text('请输入PIN码'),
  123. content: SizedBox(
  124. width: 50.0.wp,
  125. child: TextField(
  126. onChanged: (v) {
  127. pin = v;
  128. },
  129. maxLines: 1,
  130. maxLength: 8,
  131. style: const TextStyle(color: Colors.white),
  132. )),
  133. onCancel: () => Get.back(),
  134. onConfirm: () {
  135. isCancel = false;
  136. Get.back();
  137. },
  138. ));
  139. }
  140. if (!isCancel) {
  141. App.to.selectedMapId.value = data.mapId;
  142. Get.toNamed(RouteName.mapTO);
  143. // Get.to(
  144. // () => MapToView(
  145. // mapId: App.to.selectedMapId.value,
  146. // // mapName: data.name,
  147. // // pin: pin,
  148. // // isDirectIn: false,
  149. // ),
  150. // binding: MapToView.bindings());
  151. }
  152. }
  153. @override
  154. Widget build(BuildContext context) {
  155. return GestureDetector(
  156. onTap: data.isOpen ? onTap : null,
  157. child: Card(
  158. color: Colors.white,
  159. surfaceTintColor: Colors.white,
  160. shape: const RoundedRectangleBorder(
  161. borderRadius: BorderRadius.all(Radius.circular(5.44))),
  162. clipBehavior: Clip.antiAlias,
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.start,
  165. children: [
  166. AspectRatio(aspectRatio: 1, child: wImage()),
  167. Expanded(
  168. child: Padding(
  169. padding: const EdgeInsets.all(6.6),
  170. child: Column(
  171. mainAxisAlignment: MainAxisAlignment.start,
  172. crossAxisAlignment: CrossAxisAlignment.start,
  173. children: [
  174. Text(
  175. data.name,
  176. style: const TextStyle(
  177. fontSize: 13.6,
  178. fontWeight: FontWeight.w500,
  179. ),
  180. textAlign: TextAlign.start,
  181. maxLines: 1,
  182. overflow: TextOverflow.ellipsis,
  183. ),
  184. Text(
  185. data.description,
  186. style: const TextStyle(
  187. color: Color(0xffc6c6c6),
  188. fontSize: 11,
  189. fontWeight: FontWeight.w500,
  190. ),
  191. textAlign: TextAlign.start,
  192. maxLines: 1,
  193. overflow: TextOverflow.ellipsis,
  194. ),
  195. const SizedBox(height: 3),
  196. Row(
  197. crossAxisAlignment: CrossAxisAlignment.end,
  198. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  199. children: [
  200. Row(
  201. crossAxisAlignment: CrossAxisAlignment.center,
  202. mainAxisAlignment: MainAxisAlignment.start,
  203. children: [
  204. Image.asset(Assets.imagesIcRuler,
  205. height: 1.0.wp),
  206. const SizedBox(width: 1),
  207. Text('1:${data.mapScaleNumber}',
  208. style: const TextStyle(
  209. color: Colors.black, fontSize: 10)),
  210. const SizedBox(width: 6),
  211. ],
  212. ),
  213. Row(
  214. crossAxisAlignment: CrossAxisAlignment.center,
  215. mainAxisAlignment: MainAxisAlignment.end,
  216. children: [
  217. const Icon(
  218. Icons.location_on,
  219. size: 13,
  220. color: Color(0xffaaaaaa),
  221. ),
  222. const SizedBox(width: 1),
  223. // getDistanceText(data),
  224. Text("${data.distanceKm.toStringAsFixed(1)} km",
  225. style: const TextStyle(
  226. color: Colors.black, fontSize: 10))
  227. ],
  228. ),
  229. // HardLevel(data.level),
  230. ],
  231. )
  232. ],
  233. ))),
  234. ],
  235. ),
  236. ),
  237. );
  238. }
  239. Widget wImage() {
  240. return Stack(
  241. children: [
  242. SizedBox(
  243. height: double.infinity,
  244. // height: 12.85.wp,
  245. child: AppNetImage(netImage: data.image, fit: BoxFit.fitHeight)),
  246. data.isOpen
  247. ? const SizedBox()
  248. : Container(
  249. width: double.infinity,
  250. height: double.infinity,
  251. color: Colors.white.withAlpha(178),
  252. alignment: Alignment.center,
  253. child: const Text(
  254. '待开放',
  255. style: TextStyle(color: Color(0xffff6203), fontSize: 15.24),
  256. ),
  257. )
  258. ],
  259. );
  260. }
  261. Widget getDistanceText(MapInfo data) {
  262. return Obx(() {
  263. final myPosition = controller.myPosition;
  264. var str = '--';
  265. if (myPosition != null) {
  266. final p = data.position;
  267. str = p.distance(myPosition).toString();
  268. }
  269. return Text(str,
  270. style: const TextStyle(color: Colors.black, fontSize: 10));
  271. });
  272. }
  273. }
  274. void main() {
  275. Mock.initServices();
  276. PageTopController pageTopController = Get.put(PageTopController());
  277. // pageTopController.mapName.value = "济南泉城公园";
  278. // pageTopController.mapName.value = "济南森林公园风景区定向运动济南森林公园风景区定向运动";
  279. Get.put(MapListController());
  280. runPreview(const MapListView());
  281. }