map_page.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'package:common_pub/model/distance.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:track_offical/service/api.dart' as api;
  5. import 'package:track_offical/utils.dart';
  6. import 'package:common_pub/model/position.dart' as m;
  7. import '../../../generated/assets.dart';
  8. typedef MapInfo = api.ToMapSimpleV2;
  9. class MapPageController extends GetxController {
  10. @override
  11. void onInit() {
  12. super.onInit();
  13. mapGetMore();
  14. }
  15. Future<void> mapGetMore() async {
  16. if (isMapGetMoreLoading.value) {
  17. return;
  18. }
  19. isMapGetMoreLoading.value = true;
  20. await tryApi(() async {
  21. final r = await api.ApiService.to.stub.toMapListV2(api.MapListRequestV2()
  22. ..limit = 20
  23. ..offset = mapList.length);
  24. mapList.addAll(r.list);
  25. return;
  26. }, onFinally: () {
  27. isMapGetMoreLoading.value = false;
  28. });
  29. mapListScrollController.addListener(() {
  30. if (mapListScrollController.position.pixels ==
  31. mapListScrollController.position.maxScrollExtent) {
  32. //达到最大滚动位置
  33. mapGetMore();
  34. }
  35. });
  36. }
  37. final mapList = <MapInfo>[].obs;
  38. final isMapGetMoreLoading = false.obs;
  39. final mapListScrollController = ScrollController();
  40. final Rx<m.Position?> position = Rx(null);
  41. }
  42. class MapPage extends StatelessWidget {
  43. const MapPage({super.key});
  44. @override
  45. Widget build(BuildContext context) {
  46. return GetBuilder(
  47. init: MapPageController(),
  48. builder: (c) {
  49. return Container(
  50. width: double.infinity,
  51. height: double.infinity,
  52. margin: const EdgeInsets.all(20),
  53. padding: const EdgeInsets.fromLTRB(58, 28, 58, 28),
  54. decoration: BoxDecoration(
  55. color: Colors.white, borderRadius: BorderRadius.circular(16)),
  56. child: Column(
  57. children: [
  58. Row(
  59. children: [
  60. Container(
  61. width: 14,
  62. height: 14,
  63. decoration: const BoxDecoration(
  64. shape: BoxShape.circle, color: Colors.blue),
  65. ),
  66. const Text('地图列表'),
  67. ],
  68. ),
  69. Expanded(
  70. child: Obx(() => GridView.builder(
  71. itemCount: c.mapList.length,
  72. controller: c.mapListScrollController,
  73. scrollDirection: Axis.horizontal,
  74. gridDelegate:
  75. const SliverGridDelegateWithFixedCrossAxisCount(
  76. //设置列数
  77. crossAxisCount: 2,
  78. //设置横向间距
  79. crossAxisSpacing: 10,
  80. //设置主轴间距
  81. mainAxisSpacing: 10,
  82. childAspectRatio: 0.66),
  83. itemBuilder: (context, i) {
  84. return GalleryCardWidget(data: c.mapList[i], position: c.position.value);
  85. })))
  86. ],
  87. ),
  88. );
  89. });
  90. }
  91. }
  92. class GalleryCardWidget extends StatelessWidget {
  93. final MapInfo data;
  94. final m.Position? position;
  95. const GalleryCardWidget({
  96. super.key,
  97. required this.data,
  98. required this.position});
  99. void onTap() async {
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. var distance = '--';
  104. if ( data.hasDistance()) {
  105. distance = Distance(m: data.distance).toString();
  106. }
  107. return GestureDetector(
  108. onTap: onTap,
  109. child: Card(
  110. color: Colors.white,
  111. surfaceTintColor: Colors.white,
  112. shape: const RoundedRectangleBorder(
  113. borderRadius: BorderRadius.all(Radius.circular(5.44))),
  114. clipBehavior: Clip.antiAlias,
  115. child: Column(
  116. crossAxisAlignment: CrossAxisAlignment.start,
  117. children: [
  118. AspectRatio(aspectRatio: 1, child: wImage()),
  119. Expanded(
  120. child: Padding(
  121. padding: const EdgeInsets.all(6),
  122. child: Column(
  123. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  124. crossAxisAlignment: CrossAxisAlignment.start,
  125. children: [
  126. Text(
  127. data.name,
  128. style: const TextStyle(
  129. fontSize: 15.24,
  130. fontWeight: FontWeight.w500,
  131. ),
  132. textAlign: TextAlign.start,
  133. maxLines: 1,
  134. overflow: TextOverflow.ellipsis,
  135. ),
  136. Text(
  137. data.description,
  138. style: const TextStyle(
  139. fontSize: 19,
  140. color: Color(0xffc6c6c6),
  141. ),
  142. textAlign: TextAlign.start,
  143. maxLines: 1,
  144. overflow: TextOverflow.ellipsis,
  145. ),
  146. const Spacer(),
  147. DefaultTextStyle(
  148. style: const TextStyle(
  149. color: Colors.black, fontSize: 14),
  150. child: Row(
  151. crossAxisAlignment: CrossAxisAlignment.end,
  152. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  153. children: [
  154. Image.asset(Assets.imagesIcMapScale,
  155. height: 14),
  156. Text(' 1:${data.mapScaleNumber}'),
  157. const Spacer(),
  158. Image.asset(Assets.imagesIcLocation,
  159. height: 14),
  160. Text(' $distance'),
  161. ],
  162. ))
  163. ],
  164. ))),
  165. ],
  166. ),
  167. ),
  168. );
  169. }
  170. Widget wImage() {
  171. return Stack(
  172. children: [
  173. SizedBox(
  174. height: double.infinity,
  175. // child: AppNetImage(netImage: data.image, fit: BoxFit.fitHeight)
  176. ),
  177. Container(
  178. width: double.infinity,
  179. height: double.infinity,
  180. color: Colors.white.withAlpha(178),
  181. alignment: Alignment.center,
  182. child: const Text(
  183. '待开放',
  184. style: TextStyle(color: Color(0xffff6203), fontSize: 15.24),
  185. ),
  186. )
  187. ],
  188. );
  189. }
  190. }