CarsCard.dart 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. import 'package:get/get_core/src/get_main.dart';
  6. import '../models/entities/CardInfo.dart';
  7. import '../models/entities/CardListModel.dart';
  8. import '../pages/OrderConfirmation/index.dart';
  9. import '../pages/machinery/detail/index.dart';
  10. import '../pages/machinery/map/index.dart';
  11. import 'LinearGradientText.dart';
  12. class CarsCard extends StatefulWidget {
  13. final CardListModel item;
  14. const CarsCard({Key? key, required this.item}) : super(key: key);
  15. @override
  16. _CarsCardPage createState() => _CarsCardPage(item);
  17. }
  18. class _CarsCardPage extends State<CarsCard> {
  19. final CardListModel item;
  20. _CarsCardPage(this.item);
  21. setMorKm () {
  22. String n = '';
  23. if (item.distance !=null) {
  24. if ((item.distance??0) >= 1000) {
  25. n = ((item.distance??0) / 1000).toStringAsFixed(2).toString() + '公里';
  26. } else {
  27. n = item.distance.toString() + '米';
  28. }
  29. } else {
  30. n = '0m';
  31. }
  32. return n;
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Container(
  37. margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
  38. decoration: BoxDecoration(
  39. color: Color(0xfff2f2f2),
  40. ),
  41. width: 345.w,
  42. // height: 389.h,
  43. child: Column(
  44. children: [
  45. GestureDetector(
  46. onTap: () {
  47. Get.to(MachineryDetailPage(),arguments: {'id':item.machineryId,'km':setMorKm().toString()});
  48. },
  49. child: Image.network(
  50. item.thumb.toString(),
  51. width: 345.w,
  52. height: 230.h,
  53. fit: BoxFit.cover,
  54. ),
  55. ),
  56. Container(
  57. padding: EdgeInsets.fromLTRB(15, 20, 0, 0),
  58. child: Row(
  59. crossAxisAlignment: CrossAxisAlignment.start,
  60. verticalDirection: VerticalDirection.up,
  61. children: <Widget>[
  62. Container(
  63. width: 210.w,
  64. child: Text(
  65. item.name.toString(),
  66. softWrap: true,
  67. textAlign: TextAlign.left,
  68. overflow: TextOverflow.ellipsis,
  69. style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  70. ),
  71. ),
  72. ],
  73. ),
  74. ),
  75. Container(
  76. padding: const EdgeInsets.fromLTRB(19, 0, 0, 0),
  77. child: Row(
  78. crossAxisAlignment: CrossAxisAlignment.start,
  79. verticalDirection: VerticalDirection.up,
  80. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  81. children: <Widget>[
  82. Container(
  83. child: LinearGradientText(
  84. colors: const <Color>[
  85. Color(0xFFFA7878),
  86. Color(0xFFB61515),
  87. ],
  88. child: RichText(
  89. text: TextSpan(children: <InlineSpan>[
  90. TextSpan(
  91. text: (item.price! / 100).toString(),
  92. style: TextStyle(
  93. fontSize: 22,
  94. fontWeight: FontWeight.bold,
  95. )),
  96. TextSpan(
  97. text: "元/",
  98. style: TextStyle(
  99. fontSize: 22,
  100. fontWeight: FontWeight.bold,
  101. )),
  102. TextSpan(
  103. text: "公顷",
  104. style: TextStyle(
  105. fontSize: 12,
  106. fontWeight: FontWeight.bold,
  107. )),
  108. ]),
  109. ),
  110. ),
  111. ),
  112. Align(
  113. widthFactor: 1.2,
  114. heightFactor: 1.2,
  115. alignment: Alignment(1.2, -5),
  116. child: Container(
  117. margin: EdgeInsets.only(right: 13),
  118. width: 86.w, //+6
  119. height: 44.h, //+10
  120. child: ElevatedButton(
  121. onPressed: () {
  122. Get.toNamed('/orderConfirmation',
  123. arguments: {'machineryId': item.machineryId});
  124. },
  125. child: const Text(
  126. "预约",
  127. style: TextStyle(
  128. fontSize: 19,
  129. color: Colors.white,
  130. fontWeight: FontWeight.bold),
  131. ),
  132. style: ButtonStyle(
  133. backgroundColor:
  134. MaterialStateProperty.all(const Color(0xFFFF703B)),
  135. shape: MaterialStateProperty.all(
  136. const RoundedRectangleBorder(
  137. //这个0像素圆角style如果删掉的话,按钮会变成默认样式,自带圆角
  138. borderRadius:
  139. BorderRadius.all(Radius.circular(0)))),
  140. ),
  141. ),
  142. ),
  143. ),
  144. ],
  145. ),
  146. ),
  147. // 地址信息 进入地图
  148. Container(
  149. padding: EdgeInsets.fromLTRB(19, 20, 0, 10),
  150. child: Row(
  151. children: [
  152. Image.asset(
  153. "images/gpsImgae.png",
  154. width: 11.w,
  155. height: 13.h,
  156. fit: BoxFit.cover,
  157. ),
  158. Container(
  159. padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
  160. width: 300.w,
  161. child: Row(
  162. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  163. children: [
  164. Container(
  165. child: Row(
  166. children: [
  167. Text(
  168. '距离当前位置',
  169. style: TextStyle(
  170. fontSize: 15, fontWeight: FontWeight.bold),
  171. ),
  172. Text(
  173. setMorKm().toString(),
  174. style: TextStyle(
  175. fontSize: 15, fontWeight: FontWeight.bold),
  176. ),
  177. ],
  178. ),
  179. ),
  180. GestureDetector(
  181. child: Text(
  182. '进入地图 >>',
  183. style: TextStyle(
  184. fontSize: 15, fontWeight: FontWeight.bold),
  185. ),
  186. onTap: () {
  187. print('进入地图');
  188. Get.toNamed('/machineryMap',
  189. arguments: {'id':item.machineryId,'km':setMorKm().toString()});
  190. },
  191. )
  192. ],
  193. )),
  194. ],
  195. )),
  196. ],
  197. ),
  198. );
  199. }
  200. }