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